Hash-Table
LeetCode 387: First Unique Character in a String
·1 min
LeetCode
Easy
Hash-Table
String
Queue
Counting
LeetCode 387 note: count first, then scan left to right for the first character with count 1
LeetCode 383: Ransom Note
·1 min
LeetCode
Easy
Hash-Table
String
Counting
LeetCode 383 note: every character’s demand in ransomNote must not exceed its supply in magazine; an empty Counter difference means yes
LeetCode 350: Intersection of Two Arrays II
·1 min
LeetCode
Easy
Array
Hash-Table
Two-Pointers
Binary-Search
LeetCode 350 note: an intersection keeping multiplicity, where Counter’s & takes the smaller count from each side
LeetCode 349: Intersection of Two Arrays
·1 min
LeetCode
Easy
Array
Hash-Table
Two-Pointers
Binary-Search
LeetCode 349 note: convert both arrays to sets and intersect them
LeetCode 290: Word Pattern
·1 min
LeetCode
Easy
Hash-Table
String
LeetCode 290 note: pattern characters and words must correspond one to one; use two dicts or compare set sizes
LeetCode 268: Missing Number
·1 min
LeetCode
Easy
Array
Hash-Table
Math
Binary-Search
LeetCode 268 note: the sum of 0..n minus the array’s sum is the missing number, which may be 0
LeetCode 242: Valid Anagram
·2 mins
LeetCode
Easy
Hash-Table
String
Sorting
LeetCode 242 note: two strings are anagrams exactly when their character counts match; compare Counters or sorted strings
LeetCode 219: Contains Duplicate II
·2 mins
LeetCode
Easy
Array
Hash-Table
Sliding-Window
LeetCode 219 note: a hash map stores each value’s last index; only the most recent occurrence needs a distance check
LeetCode 217: Contains Duplicate
·1 min
LeetCode
Easy
Array
Hash-Table
Sorting
LeetCode 217 note: if converting to a set shortens the array, there is a duplicate
LeetCode 205: Isomorphic Strings
·2 mins
LeetCode
Easy
Hash-Table
String
LeetCode 205 note: characters must map one to one; it holds when the distinct characters and distinct pairs all have the same count
LeetCode 202: Happy Number
·1 min
LeetCode
Easy
Hash-Table
Math
Two-Pointers
Floyds-Cycle-Finding-Algorithm
LeetCode 202 note: repeatedly take the sum of squared digits, which reaches 1 or enters a cycle; detect it with a set of seen numbers or fast and slow pointers
LeetCode 169: Majority Element
·2 mins
LeetCode
Easy
Array
Hash-Table
Divide-and-Conquer
Sorting
LeetCode 169 note: Boyer-Moore voting, where different values cancel in pairs and the survivor is the one appearing more than half the time