← All questions
MediumCoding
Check if a Parentheses String Can Be Valid
Asked at
Meta
ServiceNow
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Reject odd-length strings immediately.
- 02Scan left to right, treating unlocked positions as opens, and reject an unavoidable close-heavy prefix.
- 03Scan right to left, treating unlocked positions as closes, and reject an unavoidable open-heavy suffix.
- 04Reject odd lengths before either directional feasibility scan.
Reference answer
Then expect these follow-ups
Why are both directional scans necessary?
Tests: greedy proof
How would you construct one valid assignment?
Tests: reconstruction
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question