Mirror promo codes

strings

Mirror promo codes

Airbnb Python Interview Question

Airbnb's marketing team is launching special promo codes that read the same forwards and backwards. Codes may mix capital letters, digits, dashes and spaces.

Write a function is_mirror_code(code) that returns True if the code reads the same forwards and backwards when you ignore capital letters and every character that is not a letter or a digit, and False otherwise.

Asked of

  • Data Engineer
  • Data Scientist
  • Analytics Engineer
  • ML Engineer
  • AI Engineer

Example 1

Input

is_mirror_code("Level")

Output

True

Example 2

Input

is_mirror_code("A1-b-B1a")

Output

True

Example 3

Input

is_mirror_code("shop42")

Output

False

Explanation

In the first example, "Level" reads the same backwards once capital letters are ignored, so the answer is True. In the second example, the dashes are ignored and "a1bb1a" reads the same both ways. In the third example, "shop42" backwards is "24pohs", so the answer is False.

Submit also runs 3 hidden test cases that check edge cases.