Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Check String Anagrams

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

Your question is Check String Anagrams. 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

The i2c processing platform receives transaction and cardholder name strings from different channels. Implement a function that determines whether two strings are anagrams after normalization.

Two strings are anagrams when they contain the same alphanumeric characters with the same frequencies, regardless of order. Matching must be case-insensitive, and all non-alphanumeric characters, including spaces and punctuation, must be ignored. Treat characters according to Python's Unicode isalnum() and casefold() behavior.

Formal Specification

Implement are_anagrams(first, second), which accepts two strings and returns a boolean. Normalize each string by retaining only alphanumeric characters and applying casefold(), then compare their character frequencies.

Constraints

  • 0 <= len(first), len(second) <= 100,000
  • Inputs are Unicode strings
  • Comparison is case-insensitive
  • All non-alphanumeric characters must be ignored

Function Signature

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