Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check for balanced Paranthesis

Easy Acceptance 28.56% Points 20.00

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
Amazon Microsoft Walmart Adobe Google + 2 more
Topics
Stack
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions