Skip to content

Latest commit

 

History

History

23-06-2024

Go To Problem

Print Bracket Number

Easy
Accuracy: 51.19% Points: 2
Given a string str, the task is to find the bracket numbers, i.e., for each bracket in str, return i if the bracket is the ith opening or closing bracket to appear in the string.

💡Example 1:

Input :
  str = "(aa(bdc))p(dee)"
Output :
  1 2 2 1 3 3
Explanation:
      The highlighted brackets in
      the given string (aa(bdc))p(dee) are
      assigned the numbers as: 1 2 2 1 3 3.

💡Example 2:

Input:
  str = "(((()("
Output: 
   1 2 3 4 4 5
Explanation: 
    The highlighted brackets in
    the given string (((()( are assigned
    the numbers as: 1 2 3 4 4 5

Expected Time Complexity:

O(|str|)

Expected Space Complexity:

O(|str|)

Constraints:

1 <= |str| <= 105

str contains lowercase English alphabets, and '(', ')' characters

At any index, the number of opening brackets is greater than or equal to closing brackets

Company Tag:

Topic Tags:

Codes: