Tag Validator

Asked atMicrosoft
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Require the document to begin with an opening tag.
  2. 02Scan tags and CDATA blocks with index bounds checks.
  3. 03Push valid opening names and match every closing name to stack top.
  4. 04Reject trailing text after the root closes and accept only an empty final stack.

Reference answer

Then expect these follow-ups

  • Why is a stack necessary rather than a set?

    Tests: nesting order

  • How would you report the first syntax error?

    Tests: parser diagnostics

Hiring now

Get the Microsoft interview, not just the prep

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
Or practice this question first

Next question