Question bank › Stack
Dsa Stack Easy

The XML Depth Weaver

Given a simplified XML-like string using tags like '(tag)' and '(/tag)', determine the maximum nesting depth and the name of the tag at that depth. If multiple tags exist at the same maximum depth, return the one that appeared first. If the tags are improperly nested (mismatched), print 'INVALID'. Input: A single string of tags. Output: The tag name and its depth (0-indexed) separated by a space, or 'INVALID'. Example: Input: (root)(a)(/a)(b)(c)(/c)(/b)(/root) Output: c 2 (Explanation: 'root' is depth 0, 'a' and 'b' are depth 1, 'c' is depth 2.)

Key concepts

stackstring-parsing

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.