Hello
I have a task to check if an html tag is valid
but honestly I am stuck on this for hours without knowing what to do exactly. How to compare the opening tag with closing tag? there are many possibilities that may arise for closing tag and hardcoding them in if statments obviously wouldnt work..
May you pls guide me ?
Thanks in advance
Implement a function that checks if a given HTML-like string has properly nested tags.
Use a stack for the solution. Tags appear as <tag> and </tag>.
Rules
• Tags must be closed with the correct corresponding closing tag.
• Tags must be closed in the correct order.
Example Inputs
Input: "<html><body></body></html>"
Input: "<div><p></div></p>"
Input: "<a><b></b></a>"
Output: Valid
Output: Invalid
Output: Valid