You are given a string s that contains a mix of brackets: , (), and []. Your goal is to determine if the brackets in the string are balanced. A string is considered balanced if every opening bracket has a corresponding closing bracket, and the brackets are properly nested in the correct order.
Examples
Example 1
Example 1
Input: s = "{[()]}"
Output: True
Explanation: The brackets are correctly nested and matched: , [ has a corresponding ], ( has a corresponding ).
Hints
Hint 1
Expected Time Complexity: O(n)
Hint 2
Expected Auxiliary Space: O(n)
Constraints
1 <= s.size() <= 10^6
s[i] ? {'{', '}', '(', ')', '[', ']'}
Companies
AmazonMicrosoftWalmartAdobeGoogle+ 2 more
Topics
Stack
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.
Solution.csC#JavaPythonC++Javascript
1
2
3
4
5
6
7
8
9
10
Unlock the code editor
Sign in to write, run, and submit your solution against the full test suite.