1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress

Two Sum
Use hashmap: value -> index
For each x at index i:
Compute need = target - x
If need in hashmap, return [hashmap[need], i]
Store x: i
Keeps lookup in O(1)

Best Time to Buy and Sell Stock
Track minimum price so far:
Update min_price
Compute price - min_price
Keep max profit
One pass, O(n)

Product of Array Except Self
No division:
Build prefix products
Build suffix products
Answer at i = prefix[i] * suffix[i]
Or do prefix in result array, then multiply by running suffix
O(n) time, O(1) extra space excluding output

Maximum Subarray
Kadane’s algorithm:
curr = max(num, curr + num)
best = max(best, curr)
At each index, either start fresh or extend previous
O(n)

Contains Duplicate
Use a set:
If number already in set, return True
Else add it
O(n) average

Maximum Product Subarray
Track both max and min product ending at current index:
Negative number can flip min to max
Update curMax, curMin
Track global max
Need both because of negatives
O(n)

Search in Rotated Sorted Array
Modified binary search:
Check mid
One half is always sorted
Decide whether target lies in sorted half
Move left/right accordingly
O(log n)

3Sum
Sort first:
Fix index i
Use two pointers l, r for remaining part
Move based on sum
Skip duplicates for i, l, r
O(n^2)

Container With Most Water
Two pointers at both ends:
Area = min(height[l], height[r]) * (r-l)
Move shorter line inward
Only shorter side can possibly improve area
O(n)

Sliding Window Maximum
Use monotonic decreasing deque of indices:
Remove indices out of window
Pop smaller values from back
Push current index
Front is max of current window
O(n)

Longest Substring Without Repeating Characters
Expand right pointer
While duplicate exists, shrink left
Track max window size
O(n)

Minimum Size Subarray Sum
Sliding window for positive numbers:
Expand right and add to sum
While sum >= target, update answer and shrink left
Because all numbers are positive, shrinking is valid
O(n)

Minimum Window Substring
Sliding window + frequency counts:
Count chars needed from t
Expand right, reduce needed counts
When all requirements met, shrink left to minimum valid window
Track best window
Classic variable-size sliding window

Sort Colors
Dutch National Flag:
left for 0s, right for 2s, i scans
If 0: swap with left, move both
If 2: swap with right, move right
If 1: just move i
O(n), in-place

Palindromic Substrings
Each index is center for odd palindrome
Each gap is center for even palindrome
Expand while chars match
Count every valid expansion
O(n^2)

Merge Sorted Array
Fill from the back:
Pointer i at end of nums1 valid part
Pointer j at end of nums2
Pointer k at end of nums1 total size
Put larger of nums1[i] and nums2[j] at k
Avoids shifting elements

Daily Temperatures
Monotonic decreasing stack of indices:
For each day, while current temp > stack top temp
Pop index and set answer as difference in indices
Push current index
Next greater element pattern

Merge Intervals
Sort by start:
Start with first interval
If current overlaps last merged, extend end
Else append as new interval
O(n log n) because of sorting

Non-overlapping Intervals
Greedy by end time:
Sort by interval end
Keep interval with smallest end
If next interval overlaps, remove it
Else keep it
Equivalent to maximizing number kept

First Missing Positive (H)
Place each number x in index x-1:
While 1 <= x <= n and not already in correct place, swap
After placement, first index i where nums[i] != i+1 gives answer i+1
If all correct, answer is n+1
O(n), in-place

Longest Consecutive Sequence
Use set:
For each number, only start counting if num-1 not in set
Extend forward while num+1 exists
Track longest length
Each sequence counted once
O(n) average

Jump Game
Greedy from right:
Start goal at last index
Move leftward
If i + nums[i] >= goal, update goal = i
At end, can reach if goal == 0
Work backwards to see if each index can reach goal

Subarray Sum Equals K
Prefix sum + hashmap of frequencies:
Maintain running sum s
Need previous prefix s-k
Add count of s-k to answer
Store frequency of s
Initialize hashmap with {0:1}
Handles negatives too

Maximum Number of Vowels
Fixed-size sliding window:
Count vowels in first window of size k
Slide window: add new char, remove old char
Track max count
O(n)