Valid Anagram - CA14
My Thinking and Approach Introduction In this problem, I was given two strings and asked to check whether one string is an anagram of the other. An anagram means both strings contain the same chara...

Source: DEV Community
My Thinking and Approach Introduction In this problem, I was given two strings and asked to check whether one string is an anagram of the other. An anagram means both strings contain the same characters with the same frequency but possibly in a different order. Problem Statement Given two strings s and t Return true if t is an anagram of s Otherwise return false Conditions: Strings contain only lowercase English letters My Initial Thought At first, I considered: Sorting both strings Comparing them If both sorted strings are equal, then they are anagrams. Key Observation Instead of sorting: I can count frequency of each character Compare frequencies of both strings Optimized Approach I decided to: Use a dictionary to count characters Compare counts Logic: If lengths are not equal → return false Count characters of first string Decrease count using second string If all counts become zero → valid anagram My Approach (Step-by-Step) If length of s and t are not equal → return false Create a