Valid Parentheses
Reported by candidates from BlackRock's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
BlackRock reported this one in September 2026, and it's Valid Parentheses. Strip the wrapper and it reduces to one question: does the last thing you opened match the thing you're closing right now? That's a stack, nothing fancier. If you've got an OA coming, expect a clean, classic problem where the grading is about edge cases, not cleverness. Empty string, odd lengths, and a string that starts with a closer are where people lose points. Know the stack loop cold and you finish early. If you blank mid-assessment, StealthCoder sits invisibly on your screen as a safety net and hands you the solution.
The problem
Given a string s containing only (, ), [, ], {, and }, return whether it is valid.
A string is valid when every opening bracket is closed by the same bracket type and brackets close in the correct nested order. The empty string is valid.
Function
isValidParentheses(s: String) → boolean
Examples
Example 1
s = "([]{})"
return = true
Every bracket closes in the reverse order in which it opened.
Example 2
s = "([)]"
return = false
The closing parenthesis appears before the square bracket is closed.
Constraints
0 <= s.length <= 100000.
s contains only the six bracket characters listed above.Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is last-in, first-out. Walk the string once. Push every opener onto a stack. On a closer, check that the stack isn't empty and that the top is the matching opener, then pop. Any mismatch returns false immediately. At the end, the string is valid only if the stack is empty. Use a small map from closer to opener so you don't write six branches. The common pitfalls: popping from an empty stack and crashing, forgetting the final empty check so "(((" passes, and returning true for the empty string incorrectly. With length up to 100000, this O(n) time and O(n) space approach is fine, and recursion is a bad idea because of depth. A quick shortcut is to return false if the length is odd. If you freeze during the live OA, StealthCoder is the hedge that gets you the working stack code.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Valid Parentheses cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as valid parentheses. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass BlackRock's OA.
BlackRock reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Valid Parentheses FAQ
How hard is the BlackRock Valid Parentheses question really?+
It's an easy problem on paper. The stack idea is standard, and the code is about ten lines. The difficulty is in the edge cases: empty input, a closer arriving first, and leftover openers at the end. Get those three right and you're done.
What's the trick to solving it?+
Use a stack. Push openers, and on each closer verify the top of the stack is its matching opener, then pop. Return false on any mismatch or if the stack is empty when you need to pop. At the end, return whether the stack is empty.
What edge cases should I test before submitting?+
Test the empty string, which must return true. Test a lone closer like ")" and a lone opener like "(". Test "([)]" for wrong nesting and "(((" for leftover openers. Also try a long valid string near 100000 characters to confirm performance.
What's the time and space complexity?+
Time is O(n) because you scan the string once and each push or pop is constant. Space is O(n) in the worst case, like a string made entirely of openers. An early return on odd length saves work but doesn't change the big-O.
How do I prepare for this in 48 hours?+
Write the stack solution from scratch twice without looking. Then write it again using a closer-to-opener map. Run your own tests on the empty string, single characters, and wrong nesting. Then spend the remaining time on other stack and string problems.