DSA · Build it
Valid parentheses (LeetCode 20)
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Given a string of brackets, ()[]{}, return whether it's balanced.
Then
Follow-ups the interviewer asks next
- Ignore non-bracket characters.
- Minimum removals to make it valid.
- Validate nested HTML tags like <div><span></span></div>.
- Longest valid substring.
The answer
What a strong answer covers
- a stack and a closer → opener map; push openers, on a closer compare with the top; valid only if the stack is empty at the end; odd-length early exit; O(n) time, O(n) space; for HTML tags, parse tag names and skip void and self-closing tags.
The red pen
Common traps
Avoid:counting brackets only (fails on "([)]"); popping an empty stack; forgetting the final empty check.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.