TL;DR
- Searching questions are mostly about invariants and boundary correctness.
- I practice exact match, lower bound, upper bound, rotated arrays, and nearest-value search.
- In frontend interviews, the signal is usually whether I can reason precisely under edge cases.
Context
Search logic shows up in filtered lists, ranked results, infinite scroll checkpoints, timeline insertion, and versioned data lookups. It is more practical than it first looks.
The Approach
Practice these 10 medium-level questions:
- Binary Search Exact Match — build a reliable baseline.
- Find First Occurrence — left-bound variant.
- Find Last Occurrence — right-bound variant.
- Lower Bound — first index where
value >= target. - Upper Bound — first index where
value > target. - Search in Rotated Sorted Array — branch safely on sorted halves.
- Find Peak Element — search without full scan.
- Find Minimum in Rotated Array — handle shifted sorted structure.
- Closest Value to Target — compare neighbors after boundary search.
- Search 2D Matrix — flatten index math or staged binary search.
Try it in the browser
Browser Practice
Searching practice: lower bound
Implement solve(values, target) and return the first index whose value is greater than or equal to target. Return values.length if none exists.
Sample Tests
3 checks
Function name:
solveBest for JavaScript / TypeScript / JSON practice snippets.Monospace editorRuns in browser sandbox
Trade-offs
- Binary search is fast, but one off-by-one mistake can invalidate the whole solution.
- Linear search is sometimes good enough for tiny lists, but interview problems usually want the boundary invariant itself.
References
- Related: Coding Practice: Sorting
- Related: Coding Practice: Arrays