Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Match opening and closing tags

Python data engineering interview problem. Difficulty: intermediate. Pattern: Strings. About 15 minutes. Part of the Pro drill bank.

A templating engine emits opening and closing tags. A linter should reject a fragment where tags nest incorrectly, the same way brackets must balance in code.

Return whether opening and closing tags are correctly matched and nested.

Requirements

  • Every opener needs a matching closer of the right type.
  • Order matters: close the most recent unmatched opener first.

Constraints

  • A closer with no opener is not.

Examples

Input: tags_balanced('<a><b></b></a>') Output: True This input follows the stated rules and produces this output.

Topics: lakebench, python, stack.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Match opening and closing tags

Interview-style drill: Validate whether a simplified markup string has properly nested and matched tags.

Return whether opening and closing tags are correctly matched and nested.