</>
ShikshaCSLearn. Code. Grow.
🔍
☕ Support Us
ShikshaCSâ€ēPractice Problems
DSAMediumStack

Valid Parentheses (Stack)

📋 Problem

Given a string containing only '(', ')', '{', '}', '[' and ']', determine if the brackets are balanced and correctly nested.

🧭 Approach

Use a stack. Go through the string character by character — whenever you see an opening bracket, push it. Whenever you see a closing bracket, check if the top of the stack is its matching opening bracket; if yes, pop it, if no, the string is invalid. At the end, the string is valid only if the stack is empty.

← Back to all Problems