what is the time and space complexity of this problem?
Time and space complexity?
-
Time Complexity: O(2^n).
For every index there can be two options ‘{‘ or ‘}’. So it can be said that the upperbound of time complexity is O(2^n) or it has exponential time complexity. - Space Complexity: O(n).