↓Skip to main content

LeetCode

LeetCode 1431: Kids With the Greatest Number of Candies
·1 min
LeetCode Easy Array
LeetCode 1431 note: compute the maximum once; a kid is True when their candies plus the extra reach >= the maximum, since a tie counts
LeetCode 3487: Maximum Unique Subarray Sum After Deletion
·2 mins
LeetCode Easy Greedy Hash-Table Array
LeetCode 3487 note: free deletion means picking distinct values; take every non-negative one, or only the maximum when all are negative
LeetCode 2487: Remove Nodes From Linked List
·1 min
LeetCode Medium Linked-List Stack Recursion Monotonic-Stack
LeetCode 2487 note: the kept nodes are non-increasing left to right; keep a monotonic stack, pop anything smaller than the new node, then link what remains
LeetCode 3136: Valid Word
·2 mins
LeetCode Easy String
LeetCode 3136 note: length at least 3, alphanumeric only, at least one vowel and at least one consonant; digits are not consonants
LeetCode 2000: Reverse Prefix of Word
·1 min
LeetCode Easy Two-Pointers String Stack
LeetCode 2000 note: find the first index i of ch, reverse word[:i + 1] and append the rest; return the word unchanged if ch is absent
LeetCode 3131: Find the Integer Added to Array I
·1 min
LeetCode Easy Array
LeetCode 3131 note: every element gets the same x, so x is the difference of the two minimums (or of the sums divided by the length)
LeetCode 3121: Count the Number of Special Characters II
·2 mins
LeetCode Medium Hash-Table String
LeetCode 3121 note: track each letter’s last lowercase index and first uppercase index; it counts only when the former comes first
LeetCode 3120: Count the Number of Special Characters I
·1 min
LeetCode Easy Hash-Table String
LeetCode 3120 note: collect the letters seen in lowercase and in uppercase; the size of their intersection is the answer
LeetCode 735: Asteroid Collision
·2 mins
LeetCode Medium Array Stack Simulation
LeetCode 735 note: scan left to right with a stack; only a right-moving top meeting a left-moving asteroid collides, the smaller explodes and equal sizes both do
LeetCode 988: Smallest String Starting From Leaf
·1 min
LeetCode Medium String Backtracking Tree Depth-First-Search
LeetCode 988 note: DFS prepending each character so the string at a leaf already reads leaf to root, and keep the smallest
LeetCode 1814: Count Nice Pairs in an Array
·1 min
LeetCode Medium Array Hash-Table Math Counting
LeetCode 1814 note: rearrange the condition into nums[i] - rev(nums[i]) == nums[j] - rev(nums[j]), count pairs per value, and remember the modulus
LeetCode 3075: Maximize Happiness of Selected Children
·1 min
LeetCode Medium Array Greedy Sorting
LeetCode 3075 note: choose k children from the happiest, where the i-th choice loses i, floored at 0