Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Check Anagrams Efficiently

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

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

Envestnet | Tamarac may receive equivalent portfolio labels from different export sources. Implement a function that determines whether two labels are anagrams after normalization.

Two strings are normalized anagrams when they contain the same letters and digits with the same frequencies, regardless of letter case, spaces, or punctuation. Use Unicode-aware case normalization and character classification supported by Python.

Formal Specification

Implement are_anagrams(first, second). Both inputs are strings, and the function must return a Boolean:

  • Return True if the normalized strings contain identical character frequencies.
  • Return False otherwise.
  • Normalization applies casefold(), then retains only characters for which isalnum() is True.
  • Repeated characters must occur the same number of times.

Constraints

  • 0 <= len(first), len(second) <= 100,000
  • Inputs contain Unicode characters supported by Python strings
  • Digits are significant after normalization
  • Character order does not affect the result

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