LeetCode
LeetCode 16: 3Sum Closest
·2 mins
LeetCode
Medium
Array
Two-Pointers
Sorting
LeetCode 16 note: sort, fix one number, and find the other two with converging pointers, comparing the distance abs(sum - target)
LeetCode 15: 3Sum
·2 mins
LeetCode
Medium
Array
Two-Pointers
Sorting
LeetCode 15 note: sort, fix the first number, and find the other two with converging pointers, skipping equal values at all three positions to avoid duplicate triplets
LeetCode 11: Container With Most Water
·2 mins
LeetCode
Medium
Array
Two-Pointers
Greedy
LeetCode 11 note: start pointers at both ends and always move the shorter side; moving the taller side only narrows the width without raising the height
LeetCode 1189: Maximum Number of Balloons
·2 mins
LeetCode
Easy
Hash-Table
String
Counting
LeetCode 1189 note: each letter supports count // needed balloons, with l and o needed twice; take the minimum
LeetCode 1184: Distance Between Bus Stops
·1 min
LeetCode
Easy
Array
LeetCode 1184 note: a circular route has two directions; clockwise is the sum between start and destination, counterclockwise is the total minus that
LeetCode 1160: Find Words That Can Be Formed by Characters
·1 min
LeetCode
Easy
Array
Hash-Table
String
Counting
LeetCode 1160 note: a word is formable when none of its character counts exceeds chars’; sum the lengths of such words
LeetCode 1137: N-th Tribonacci Number
·2 mins
LeetCode
Easy
Math
Dynamic-Programming
Memoization
LeetCode 1137 note: like Fibonacci, roll three variables; watch the base values T0 = 0, T1 = T2 = 1 and the loop range
LeetCode 1128: Number of Equivalent Domino Pairs
·2 mins
LeetCode
Easy
Array
Hash-Table
Counting
LeetCode 1128 note: normalize each domino to (small, large) as a key and count; a key with c dominoes yields c(c - 1) / 2 pairs
LeetCode 1122: Relative Sort Array
·1 min
LeetCode
Easy
Array
Hash-Table
Sorting
Counting-Sort
LeetCode 1122 note: count first, emit values in arr2’s order, then append the remaining values in ascending order
LeetCode 1108: Defanging an IP Address
·1 min
LeetCode
Easy
String
LeetCode 1108 note: replace every . with [.]
LeetCode 1103: Distribute Candies to People
·1 min
LeetCode
Easy
Math
Simulation
LeetCode 1103 note: simulate the rounds, giving i + 1 candies on the i-th turn, and hand all the rest to the current person when short
LeetCode 1089: Duplicate Zeros
·2 mins
LeetCode
Easy
Array
Two-Pointers
LeetCode 1089 note: count the zeros to know each value’s shift, then move from back to front, writing the extra 0 when copying a zero