Trains the technique from
LeetCode 20Valid ParenthesesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A template compiler scans a source file, discards every character that is not a grouping mark, and keeps what remains in order as the string code. So code is built only from round marks ( and ), square marks [ and ], and curly marks { and }. The compiler only runs this check on files that contained at least one grouping mark.
The compiler calls the grouping sound when the marks can be paired off so that all of the following hold:
Return true when the grouping in code is sound, and false when no such pairing exists.
Example 1
The square pair and the curly pair both sit entirely inside the round pair, so nothing crosses and every mark is used exactly once.
Example 2
Pairing the round marks and the curly marks here forces the two pairs to cross, and no other pairing is available.
Example 3
There are three marks, an odd count, so at least one cannot belong to a pair.
Example 4
A single closer has no opener before it to pair with.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def is_balanced(code: str) -> bool:public boolean isBalanced(String code)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.