Problem 253587 · easy · Phase 02 Linear Data Structures

Licence Plate Template

strings · validation · iteration

A licence plate template describes the shape of a plate: A stands for one uppercase letter, 9 stands for one digit, and any other character must appear literally in the same position. Write matches_plate(plate, template) that returns True if plate fits the template exactly.

Examples

Input:  plate = "ABC-1234", template = "AAA-9999"
Output: True

Input:  plate = "AB-1234", template = "AAA-9999"
Output: False
Explanation: lengths differ.

Input:  plate = "XY 12 ZZ", template = "AA 99 AA"
Output: True

Constraints

  • 0 <= len(plate), len(template) <= 10**4, printable ASCII only
  • Lowercase letters do not count as letters for A
  • Target: O(n) time

Goals

  • Walk two strings in lockstep with zip
  • Map template characters to character classes
  • Handle a length mismatch before comparing
Starting Python…