Dsa
Stack
Medium
Condensed HTML Tag Structure
You are tasked with checking the structure of HTML-like tags in a given string. Write a function that determines if all opening tags have a corresponding closing tag and that they are correctly nested. For simplicity, consider tags as strings formed by '<' and '>'. For example, '<div><span></span></div>' is valid, while '<div><span></div></span>' is not.
Input
The input consists of a single line containing the HTML-like tags string.
Output
Print 'VALID' if the structure is correct, otherwise print 'INVALID'.
Example
Input:
<div><span></span></div>
Output:
VALID
Key concepts
stackhtmlparser
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