↓Skip to main content

Medium

LeetCode 3843: First Element with Unique Frequency
·1 min
LeetCode Medium Hash-Table Counting Array
LeetCode 3843 note: count each value, then count how many values share each count; the first element from the left whose count is its own is the answer
LeetCode 3840: House Robber V
·2 mins
LeetCode Medium Dynamic-Programming Array
LeetCode 3840 note: houses conflict only when adjacent with the same color; take a house outright when the colors differ, and do the House Robber choice only when they match
LeetCode 3839: Number of Prefix Connected Groups
·1 min
LeetCode Medium Hash-Table String Counting
LeetCode 3839 note: words sharing the first k characters are connected, so count by word[:k]; exclude words shorter than k
LeetCode 3719: Longest Balanced Subarray I
·2 mins
LeetCode Medium Hash-Table Prefix-Sum Segment-Tree Array
LeetCode 3719 note: n is only 1500, so fix the left end and extend right, maintaining distinct odds and evens in two sets
LeetCode 2838: Maximum Coins Heroes Can Collect
·2 mins
LeetCode Medium Binary-Search Prefix-Sum Sorting
LeetCode 2838 note: sort monsters by power, build coin prefix sums, and bisect_right per hero
LeetCode 1570: Dot Product of Two Sparse Vectors
·2 mins
LeetCode Medium Two-Pointers Design Hash-Table Array
LeetCode 1570 note: store only non-zero (index, value) pairs, and compute the dot product by merging the two index-sorted lists with two pointers, multiplying only on equal indices
LeetCode 1229: Meeting Scheduler
·2 mins
LeetCode Medium Two-Pointers Sorting Array
LeetCode 1229 note: sort both people’s slots, then find intersections with two pointers as in 986; the first intersection that is long enough is the earliest slot
LeetCode 3835: Count Subarrays With Cost Less Than or Equal to K
·2 mins
LeetCode Medium Sliding-Window Monotonic-Queue Queue Array
LeetCode 3835 note: cost = (max - min) × length only grows as the window grows, so a sliding window counts subarrays; two monotonic deques keep the window’s max and min
LeetCode 3834: Merge Adjacent Equal Elements
·2 mins
LeetCode Medium Stack Simulation Array
LeetCode 3834 note: a stack simulation where a new element merges with an equal top, possibly again with the new top
LeetCode 2054: Two Best Non-Overlapping Events
·2 mins
LeetCode Medium Dynamic-Programming Binary-Search Sorting Heap
LeetCode 2054 note: with at most two events, pair each event with the most valuable event that ends before it starts; sort by end time and use a prefix max with binary search
LeetCode 244: Shortest Word Distance II
·2 mins
LeetCode Medium Two-Pointers Design Hash-Table String Array
LeetCode 244 note: precompute each word’s positions (sorted by construction), then answer each query by merging the two position lists with two pointers, always advancing the smaller one
LeetCode 986: Interval List Intersections
·2 mins
LeetCode Medium Two-Pointers Sweep-Line Array
LeetCode 986 note: two pointers each hold an interval, the intersection is [max(starts), min(ends)], and the interval that ends first cannot meet anything else, so its pointer advances