Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

83. Valid Parentheses

EasyDay 25 of 60Stack & Queue

Given a string s made only of the characters (, ), {, }, [ and ], decide whether it is valid. It is valid when every opening bracket is closed by a bracket of the same type, brackets are closed in the correct order, and every closing bracket has a matching opening bracket before it.

Example 1
Input: s = "()[]{}"
Output: true
Example 2
Input: s = "([)]"
Output: false
The [ is still open when ) arrives, so the order is wrong.
Constraints
  • 1 <= s.length <= 10^4
  • `s` contains only the six bracket characters
Hints
Frequently asked at: Amazon, Microsoft, Google, Meta, TCS, Infosys, Accenture
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min