Loading…
Loading…
Given two strings s and t, print true if t is an anagram of s (same characters, same counts), false otherwise.
Input: s = anagram, t = nagaram
Output: true
Count character frequencies in both strings with a hash map (or a fixed-size array for lowercase letters) and compare — O(n) instead of sorting both strings (O(n log n)).
Line 1: s Line 2: t
Input (stdin)
Output
Input (stdin)
Output
Sign in to track solved problems and earn XP.