Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Check If Two Strings Are Anagrams

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

Your question is Check If Two Strings Are 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

Given two strings s and t, return True if t is an anagram of s, otherwise return False. Two strings are anagrams if they contain exactly the same characters with the same frequencies, possibly in a different order.

Constraints

  • 1 <= len(s), len(t) <= 10^5
  • s and t consist of printable characters
  • Character comparison is case-sensitive
  • Aim for O(n) time instead of sorting-based O(n log n)

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