Configurable Valid Parentheses
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
A stack is the whole game in this Bloomberg OA question, reported in November 2019. You get a text string and a list of two-character pairs, and you have to say whether the delimiters nest correctly and all close. Think classic valid parentheses, but the bracket types come from input instead of being hardcoded. That's the only twist. If you've seen the standard version, you already know the shape. If you blank under the timer, StealthCoder runs invisibly on your desktop as a safety net and gives you the solution live. Don't count on needing it. This one is short once you see the stack.
The problem
Each two-character string in pairs gives an opening and its matching closing character. Ignore text characters absent from all pairs. Return true when configured delimiters are correctly nested and completely closed. Function validConfiguredParentheses(text: String, pairs: String[]) → boolean Examples Example 1 text = "x<aAb>y" pairs = ["<>","aA","bB"] return = false The closer b does not match the expected A. Constraints Every pair has length two. Pair characters are globally distinct. text.length <= 10^6.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build two hash maps from pairs: closer to opener, and a set of openers. Walk the text once. If a character is an opener, push it. If it's a closer, the stack must be non-empty and its top must equal the mapped opener, otherwise return false. Pop on match. Characters in neither map get skipped. At the end, return true only if the stack is empty. The example shows the trap: in x<aAb>y, the b opens, then > arrives and the top is b, not <, so it fails. Pitfall one is forgetting the final empty check, which breaks inputs like an unclosed opener. Pitfall two is popping from an empty stack. Pairs are globally distinct, so no character is both opener and closer, and you don't need collision handling. With text up to 10^6, O(n) time is required. If the live OA freezes your head, StealthCoder is the hedge.
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 Configurable 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.
Configurable Valid Parentheses FAQ
How hard is Configurable Valid Parentheses really?+
Easy to medium. It's the standard valid parentheses problem with the bracket types passed in. If you can write the classic stack solution, you only need to swap hardcoded brackets for lookup maps built from the pairs array.
What's the trick to solving it?+
Use a stack plus a map from each closer to its opener. Push openers, and on a closer check the top of the stack matches the mapped opener. Ignore every character that isn't in any pair. Finish by checking the stack is empty.
What edge cases should I test?+
Test a closer arriving on an empty stack, an unclosed opener left at the end, text with no delimiters at all, and mismatched types like the b against A case from the example. Also test an empty text string, which should return true.
Will text length of 10^6 cause problems?+
Not with a single pass. O(n) time and up to O(n) stack space is fine. Avoid string concatenation or repeated scanning of the pairs array per character. Precompute the lookups once, and recursion is a bad idea at that size.
How do I prepare in 48 hours?+
Write the classic valid parentheses solution from memory twice. Then rewrite it using maps built from a pairs list. Practice skipping non-delimiter characters. That covers this problem and most Bloomberg-style stack variants you could see.