Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Anagram Comparison Function

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

Your question is Anagram Comparison Function. 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

Branch attribution data can contain short campaign or link identifiers that need exact string comparison. Write a function that determines whether two strings are anagrams, meaning they contain the same characters with the same frequencies, regardless of order.

Return True if the strings are anagrams and False otherwise. The comparison is case-sensitive, and every character, including letters, digits, punctuation, and spaces, must be counted exactly as provided.

Formal Specification

Implement are_anagrams(s, t).

  • Input: Two strings s and t.
  • Output: A boolean. Return True when both strings have identical character frequency maps, otherwise return False.
  • The function must not modify either input string.

Constraints

  • 0 <= len(s), len(t) <= 10^5
  • Strings may contain any standard ASCII characters
  • Comparison is case-sensitive
  • Spaces and punctuation are treated as regular characters

Function Signature

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