ORIGINAL CODING QUESTION
Maximum action nesting depth
Given a valid balanced bracket sequence encoded as 1=open and -1=close, return its maximum nesting depth.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n integer values. Print one integer as described.
Constraints
2 ≤ n ≤ 200; valid balanced sequence with tokens in {1,-1}.
Example 1
Input
4 1 1 -1 -1
Output
2
The inner action reaches depth 2.
Example 2
Input
4 1 -1 1 -1
Output
1
Sequential actions reach depth 1.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
The current nesting equals the prefix balance.
Hint 2
Opening increments and closing decrements depth.
Hint 3
Track the largest balance seen.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →