Question bank › Stack
Dsa Stack Medium

Stack Depth

You are given a representation of a nested list using brackets. Each opening bracket (either '[' or '{') indicates a new depth level in the structure. Your task is to calculate the maximum depth of the nested structure. Input: A single line containing a string that consists of the characters '[', ']', '{', '}', each with a maximum length of 10000. Output: An integer representing the maximum depth of the nested structure. Example: Input: [1, [2, {3, 4}, [5]]] Output: 3

Key concepts

stackdepthnested

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.