1/7
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

binary search
Classic template:
l = 0, r = n-1
While l <= r:
mid = (l+r)//2
Compare target with nums[mid]
Move left/right accordingly
O(log n)

Search in Rotated Sorted Array
Modified binary search:
One half is always sorted
Check if target lies in sorted half
Move to correct side
Repeat until found
O(log n)

Kth Smallest Element in a Sorted Matrix
Binary search on value range:
low = smallest, high = largest
Mid = candidate value
Count elements ≤ mid (row-wise)
If count < k → search right
Else search left
O(n log range)

Search a 2D Matrix
Treat matrix as sorted array:
Index = mid // cols, mid % cols
Apply binary search
Matrix is globally sorted
O(log (m*n))

Kth Largest Element in an Array
Quickselect:
Choose pivot
Partition into > pivot and < pivot
Recurse on correct side
Average O(n)
(Heap alternative: size k min-heap → O(n log k))

Find Minimum in Rotated Sorted Array
Binary search:
Compare nums[mid] with nums[r]
If mid > r, min is right side
Else min is left (including mid)
Stop when l == r
O(log n)

Median of Two Sorted Arrays (H)
Binary search partition:
Partition both arrays so left halves = right halves
Ensure max(left) ≤ min(right)
Median from boundary elements
Binary search on smaller array
O(log(min(m,n)))

H-Index
Sort citations:
Sort descending
Find largest h such that citations[h] ≥ h+1
Alternative:
Sort ascending and check citations[i] ≥ n-i