↓Skip to main content

LeetCode

LeetCode 1480: Running Sum of 1d Array
·1 min
LeetCode Easy Array Prefix-Sum
LeetCode 1480 note: the definition of a prefix sum, adding each element to the previous running total
LeetCode 1413: Minimum Value to Get Positive Step by Step Sum
·1 min
LeetCode Easy Array Prefix-Sum
LeetCode 1413 note: the start value plus every prefix sum must be at least 1, so it is max(1, 1 - minimum prefix sum)
LeetCode 2335: Minimum Amount of Time to Fill Cups
·1 min
LeetCode Easy Array Greedy Sorting Heap-Priority-Queue
LeetCode 2335 note: the answer is max(the largest count, ceil(total / 2)); simulating means filling one cup from each of the two largest every second
LeetCode 2231: Largest Number After Digit Swaps by Parity
·2 mins
LeetCode Easy Sorting Heap-Priority-Queue
LeetCode 2231 note: odd digits swap only with odd digits and even with even; sort each group and refill each position with the largest digit of its parity
LeetCode 2099: Find Subsequence of Length K With the Largest Sum
·1 min
LeetCode Easy Array Hash-Table Sorting Heap-Priority-Queue
LeetCode 2099 note: pick the k largest values along with their indices, then sort by index to restore the original order
LeetCode 1791: Find Center of Star Graph
·1 min
LeetCode Easy Graph
LeetCode 1791 note: the center lies on every edge, so the common endpoint of the first two edges is the answer
LeetCode 2357: Make Array Zero by Subtracting Equal Amounts
·1 min
LeetCode Easy Array Hash-Table Greedy Sorting
LeetCode 2357 note: each operation zeroes the group of the smallest positive value, so the answer is the number of distinct positive values
LeetCode 1464: Maximum Product of Two Elements in an Array
·1 min
LeetCode Easy Array Sorting Heap-Priority-Queue
LeetCode 1464 note: all values are positive, so take the two largest a and b and return (a - 1)(b - 1)
LeetCode 1337: The K Weakest Rows in a Matrix
·1 min
LeetCode Easy Array Binary-Search Sorting Heap-Priority-Queue
LeetCode 1337 note: soldiers come first in each row, so binary search the first 0 for the count; sort by (count, row index) and take k
LeetCode 165: Compare Version Numbers
·1 min
LeetCode Medium Two-Pointers String
LeetCode 165 note: split on dots, compare revision by revision as integers, and treat missing revisions of the shorter version as 0
LeetCode 109: Convert Sorted List to Binary Search Tree
·2 mins
LeetCode Medium Linked-List Divide-and-Conquer Tree Binary-Search-Tree
LeetCode 109 note: take the middle found with fast and slow pointers as the root and recurse on both halves; the height balances naturally
LeetCode 236: Lowest Common Ancestor of a Binary Tree
·2 mins
LeetCode Medium Tree Depth-First-Search Binary-Tree Binary-Lifting
LeetCode 236 note: recursion returns whichever of p or q a subtree contains; finding something on both sides means they split here, so this node is the LCA