Trains the technique from
LeetCode 1021Remove Outermost 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 sampling profiler writes one character every time control moves: ( when a function is entered and ) when it returns. The finished tape trace is therefore balanced, and it splits into root frames: a root frame is a balanced chunk of the tape that is not contained in any longer balanced chunk, so reading the tape left to right and cutting every time the open-count falls back to zero recovers the root frames in order.
The viewer already draws each root frame as its own row, so the pair of markers that encloses a root frame is redundant. Build the trimmed tape: take every root frame, drop its first and its last character, and concatenate what is left in the original order.
Return the trimmed tape as a string. It may be empty.
Example 1
The root frames are `(())` and `(()())`. Dropping the enclosing pair of each leaves `()` and `()()`, which join to `()()()`.
Example 2
The whole tape is a single root frame, so only its first and last characters go away.
Example 3
The root frames are `()` and `(())`; the first contributes nothing and the second contributes `()`.
Example 4
The root frames are `(()(()))` and `()`; the first contributes `()(())` and the second contributes nothing.
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 strip_frame_markers(trace: str) -> str:public String stripFrameMarkers(String trace)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.