Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Checking String Anagrams

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

Your question is Checking 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

Flyways may compare normalized text labels, such as route or operational messages, where two strings are equivalent if they contain the same characters with the same frequencies. Implement a function that determines whether two strings are anagrams.

Two strings are anagrams when one can be rearranged to produce the other. Treat characters as case-sensitive, and count spaces and punctuation as ordinary characters. The strings must have equal length and identical character multiplicities.

Formal Specification

Implement is_anagram(s, t), where s and t are strings. Return True if they are anagrams and False otherwise. The function must not modify either input string.

Constraints

  • 0 <= len(s), len(t) <= 10^5
  • Inputs contain printable ASCII characters
  • Comparison is case-sensitive
  • Spaces and punctuation are counted as characters

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