
Bracket Number Problem Statement
Given a string S
that contains some brackets, your task is to print the number associated with each bracket pair.
Example:
Input:
S = (pq)()
Output:
1 1 2 2
Explanation:
The first pair of opening and closing brackets is assigned the number 1, and the second pair is assigned the number 2.
Constraints:
1 ≤ T ≤ 50
- WhereT
is the number of test cases.1 ≤ |S| ≤ 10^5
- Where|S|
is the length of the string.- Time Limit: 1 Second

AnswerBot
11d

Given a string with brackets, print the number associated with each bracket pair.
Iterate through the string and maintain a stack to keep track of opening brackets
Assign a number to each pair of openin...read more

Help your peers!
Add answer anonymously...
Top Amazon Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Amazon Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app