Valid Parentheses
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
With 100000 characters possible, any approach that repeatedly strips matched pairs out of the string will crawl. That's the first thing to clock about the Bloomberg Valid Parentheses OA, reported in December 2025. It's a stack problem, and a short one. The catch is that the edge cases are where people lose points, not the core idea. If you've got an invite and 48 hours, you need the pattern cold and the pitfalls memorized. And if your mind goes blank mid-assessment, StealthCoder runs invisibly as a safety net so you're not stuck staring at an empty editor.
The problem
Given a string s containing only the bracket characters (, ), [, ], {, and }, determine whether it is valid.
A string is valid when every opening bracket is closed by the same type of bracket and brackets close in the reverse order in which they were opened. The empty string is valid.
Return true if s is valid; otherwise, return false.
Function
isValidParentheses(s: String) → boolean
Examples
Example 1
s = "()[]{}"
return = true
Each opening bracket is immediately followed by its matching closing bracket.
Example 2
s = "([{}])"
return = true
The brackets are properly nested and close in reverse opening order.
Example 3
s = "([)]"
return = false
The closing parenthesis appears before the nested square bracket is closed.
Constraints
0 <= s.length <= 100000.
Every character of s is one of ()[]{}.Reported by candidates. Source: FastPrep
Pattern and pitfall
Walk the string once. Push every opening bracket onto a stack. When you hit a closing bracket, the stack must be non-empty and its top must be the matching opener. Pop it and keep going. At the end, the stack must be empty. That's O(n) time and O(n) space. The brute force loop of replacing "()", "[]", and "{}" until nothing changes is O(n^2) on a 100000-character input, so it's the trap. Pitfalls: popping from an empty stack on input like ")", forgetting the final empty check on input like "((", and mishandling the empty string, which is valid. A map from closer to opener keeps the code tight. A quick odd-length check lets you return false early. If you freeze during the live Bloomberg OA, StealthCoder is the hedge that surfaces this exact solution.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
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 Bloomberg's OA.
Bloomberg reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Valid Parentheses FAQ
How hard is the Bloomberg Valid Parentheses question really?+
Easy if you know stacks, and a trap if you don't. The logic is about ten lines. Most failures come from missing edge cases like a lone closing bracket, leftover openers at the end, or the empty string being valid.
What's the trick to solving it?+
Use a stack. Push openers, and on each closer check the top matches, then pop. Return true only if the stack is empty at the end. Reverse-order closing is exactly what last-in-first-out gives you.
Why not just remove matching pairs repeatedly?+
With length up to 100000, repeated string replacement is quadratic in the worst case. Input like nested brackets forces many passes. The stack does it in one pass, which is what the constraint is nudging you toward.
Which edge cases should I test before submitting?+
Test the empty string (true), a single closer like ")" (false), a single opener like "(" (false), "([)]" (false), and a long nested string. Also check odd-length strings, which can never be valid and can return false immediately.
How do I prepare in 48 hours for this kind of OA?+
Write the stack solution from memory twice, in your OA language. Then do two or three related stack problems to get comfortable. Focus on clean edge-case handling and complexity explanations, since this question rewards precision over cleverness.