Solve Anagram Without Sorting
PilotSoftware Engineer · Technical ScreenLast updated
This question evaluates proficiency in string manipulation, character frequency analysis, and asymptotic time/space complexity reasoning. It is commonly asked in the coding & algorithms domain to test practical application of basic data structures (string processing and frequency-based counting), correctness under input constraints, and the ability to design efficient, linear-time solutions rather than purely conceptual reasoning.
Given two strings s and t, return true if t is an anagram of s, and false otherwise. You may not sort either string.
An anagram uses exactly the same characters with the same frequencies, but possibly in a different order.
Assume both strings contain only lowercase English letters.
Examples:
s = "listen",t = "silent"->trues = "rat",t = "car"->false
Can you solve this in linear time using a hash table or frequency-count approach?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.