Problem 479063 · medium · Phase 04 Non-Linear Data Structures

Symmetric Label Check

recursion · two indices · strings

A packaging designer wants labels that read the same forwards and backwards once spaces are ignored and letter case is disregarded. Write is_symmetric(label) returning True if the label is symmetric under those rules and False otherwise. The comparison itself must be recursive: no [::-1], reversed, or loops over the characters.

Examples

Input:  label = "Was it a rat I saw"
Output: True

Input:  label = "Rat"
Output: False

Input:  label = ""
Output: True

Constraints

  • 0 <= len(label) <= 4000; letters, digits and spaces only.
  • Only spaces are ignored; digits count as ordinary characters.
  • A recursive solution that compares from both ends needs at most len(label) / 2 levels.

Goals

  • Normalise the input before recursing
  • Recurse on a pair of indices instead of slicing
  • Stop as soon as the indices meet or cross
Starting Python…