dsa1 min read
Search a 2D Matrix II — Staircase Search O(m+n)
Search a row-column sorted 2D matrix in O(m+n) using the staircase technique from top-right corner.
Read →
1575 articles
Search a row-column sorted 2D matrix in O(m+n) using the staircase technique from top-right corner.
Place c cows in stalls to maximize the minimum distance between any two cows using binary search on the answer.
Count subarrays with sum in [lower, upper] using merge sort on prefix sums for O(n log n) complexity.
Find the picked number using binary search with the guess() API that returns -1, 0, or 1.
Count negatives in a sorted matrix in O(m+n) using the staircase approach or O(m log n) with binary search per row.