Array
LeetCode 2859: Sum of Values at Indices With K Set Bits
·1 min
LeetCode
Easy
Array
Bit-Manipulation
LeetCode 2859 note: count the set bits of the index, not of the value
LeetCode 154: Find Minimum in Rotated Sorted Array II
·1 min
LeetCode
Hard
Array
Binary-Search
LeetCode 154 note: compare with the right end as in LC 153; on equality the break could be on either side, so r -= 1, worst case O(n)
LeetCode 611: Valid Triangle Number
·2 mins
LeetCode
Medium
Array
Two-Pointers
Binary-Search
Greedy
LeetCode 611 note: sort, fix the longest side k, and use two pointers for the shorter sides; when the sum is large enough every i in between works, adding j - i at once
LeetCode 540: Single Element in a Sorted Array
·2 mins
LeetCode
Medium
Array
Binary-Search
LeetCode 540 note: before the single element every pair starts at an even index, so binary search whether nums[mid] equals nums[mid + 1] at an even mid
LeetCode 275: H-Index II
·2 mins
LeetCode
Medium
Array
Binary-Search
LeetCode 275 note: with sorted citations, find the first i where citations[i] >= n - i; the answer is n - i, in O(log n) with binary search
LeetCode 1991: Find the Middle Index in Array
·1 min
LeetCode
Easy
Array
Prefix-Sum
LeetCode 1991 note: compute the total, maintain the left sum while scanning, and get the right sum as total - left - nums[i]
LeetCode 1732: Find the Highest Altitude
·1 min
LeetCode
Easy
Array
Prefix-Sum
LeetCode 1732 note: the altitudes are prefix sums of gain starting from 0; take the maximum
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 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 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