← 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
Hiring now
ServiceNow has 794 open roles right now
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.
Customer Success Executive
Remote
CRM Senior Solution Sales Executive
Brasilia, Brasilia, Brazil
CPQ Senior Solution Sales Executive
Sao Paulo, SAO PAULO, Brazil
Next question