JavaScriptEasyStrings10 min
Check whether two strings are anagrams
Return whether two ASCII strings contain the same characters with the same multiplicities; case and spaces matter. All input is valid JSON satisfying the constraints; do not mutate the meaning of values through type coercion. Interviewers use this problem to assess compare character multiplicities instead of sorting.
Input
A JSON array [first, second] of strings.
Output
Print one compact JSON value: a boolean.
Constraints
Each string has at most 10000 ASCII characters.
Example
Input
["listen","silent"]
Output
true
Example 2 input
["x",""]
Output
false
Boundary case: Empty strings are anagrams
Public test cases (2)
Input
["listen","silent"]
Expected output
true
Input
["aab","abb"]
Expected output
false
Hints (2)
- Equal lengths are necessary
- Empty strings are anagrams
Target complexity: time O(n+m) · space O(1) for the fixed ASCII alphabet
