Source Link:
https://www.careercup.com/question?id=5633243081605120
Question:
Given a string of brackets, the task is to find an index k which
decides the number of opening brackets is equal to the number of closing
brackets.
String must be consists of only opening and closing brackets i.e. ‘(‘ and ‘)’.
An equal point is an index such that the number of opening brackets before it is equal to the number of closing brackets from and after.
Space Complexity O(n) Solution:
http://www.geeksforgeeks.org/find-equal-point-string-brackets/
Space Complexity O(1) Solution:
https://github.com/Jarosh/Exercises/wiki/Split-array-into-two-parts,-such-that-the-number-of-elements-equal-to-X-in-the-first-part-is-the-same-as-the-number-of-elements-different-from-X-in-the-other-part
The O(1) Trick:
The answer is always: "length_of_the_string - num_of_opening_brackets"
Subscribe to:
Post Comments (Atom)
Codility - Lesson 16 Greedy algorithms - 2. MaxNonoverlappingSegments
Source Link: https://app.codility.com/programmers/lessons/16-greedy_algorithms/max_nonoverlapping_segments/ Question: Located on a line ...
-
Source Link: https://app.codility.com/programmers/lessons/15-caterpillar_method/count_distinct_slices/ Question: An integer M and a...
-
Source Link: https://app.codility.com/programmers/lessons/15-caterpillar_method/count_triangles/ Question: A zero-indexed array A consi...
-
Source Link: https://codility.com/programmers/lessons/9-maximum_slice_problem/max_slice_sum/ Question: A non-empty zero-indexed array A...
No comments:
Post a Comment