A markup linter receives a document already split into tokens. A token is one of: an opening tag like <div>, a closing tag like </div>, a self-closing tag like <br/>, or plain text (any token that doesn't start with <).
Write validTags(tokens) that returns true if every opening tag is closed by a closing tag with the same name, tags never cross (so <b><i></b></i> is invalid), and no closing tag appears without a matching open tag. Self-closing tags and text never need closing.
Input: tokens = ["<div>","<p>","hello","</p>","</div>"] Output: true
p closes inside div, then div closes.
Input: tokens = ["<div>","<span>","</div>","</span>"] Output: false
div closes while span is still open inside it.
0 <= tokens.length <= 10^5Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #254 Validate Nested Markup Tags. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.