Given a string containing nested brackets, print all the “strings” in the highest/innermost bracket level. You can assume that brackets are all valid and ignore any whitespaces.
input = ( p((qsdgfsgsgd(dfggfg))) ((s(ssdgssgf))t) )”
output = [[‘dfggfg’], [‘ssdgssgf’]] (as both are at maximum 4th nested level)
Given a collection of intervals, return a maximal set of non-overlapping intervals while prioritizing the longer intervals.
input — (1,5),(2,7),(11,18)
output — (11, 18), (2, 7)
In the given example, (1,5) and (2,7) are overlapping intervals and while choosing between the two, (2,7) is chosen as 7–2 > 5–1.
Time complexity: O(N logN)
Space Complexity: O(N)