Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Anagram String Program

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Anagram String Program. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

AvaTax integrations may receive equivalent tax-related identifiers with differences in capitalization, spaces, or punctuation. Write a function that determines whether two strings are anagrams after normalization.

Two strings are normalized by converting letters to lowercase and ignoring every character that is not a letter or digit. The strings are anagrams if their normalized forms contain exactly the same characters with the same frequencies.

Formal Specification

Implement is_anagram(s, t), where s and t are strings. Return True if their normalized forms are anagrams, otherwise return False.

The function must not modify either input string. Unicode letters and digits should be considered valid alphanumeric characters by Python's isalnum() method.

Constraints

  • 0 <= len(s), len(t) <= 10^5
  • Inputs may contain Unicode letters, digits, spaces, and punctuation
  • Comparison is case-insensitive
  • Only characters where isalnum() is True are considered

Function Signature

def is_anagram(s, t):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output