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 - Where T 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...
Amazon Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter