Anagram Check
Either sort both strings and compare them, or build character frequency maps. The hash-map version is linear time and communicates counting skill well.
Check whether two strings contain the same characters with the same counts.
Tagged with hash-map
Either sort both strings and compare them, or build character frequency maps. The hash-map version is linear time and communicates counting skill well.
Check whether two strings contain the same characters with the same counts.
Iterate through the string once and increment the count for each character so the result maps each distinct character to its frequency.
Return a frequency map for all characters in a string.
Split the text into words, normalize if needed, and increment counts in a dictionary. Python collections.Counter is great, but interviewers may ask for the manual version first.
Return a frequency map for the words in a sentence.
Walk the list once, keep a set of seen values, and add repeated values into a duplicate set. Convert to a sorted list if stable output helps.
Return the duplicate values from a list of integers.
Build a frequency map for the characters, then iterate through the string a second time to return the first character whose count is one.
Return the first character in a string that appears exactly once, or an empty string if none exists.
Use a dictionary keyed by the sorted characters of each word, then append each word into the matching bucket.
Group words that are anagrams of each other and return the grouped lists.
Store items in an OrderedDict, move keys to the end whenever they are read or updated, and evict the oldest item when capacity is exceeded.
Implement an LRU cache with O(1) get and put operations.
Track how many required characters are satisfied as you grow the right edge. Once the window is valid, shrink from the left to find the smallest valid window before expanding again.
Return the smallest substring of s that contains all characters from t.
Keep a running prefix sum and a hash map of how many times each prefix sum has appeared. For each new prefix, look for prefix minus k to count matching earlier starts.
Count how many contiguous subarrays sum to k.
Build a frequency map, then select the top k items by count using a heap-based helper or a bucket sort approach.
Return the k most frequent values from an integer list.