Field note / fundamentals

publishedupdated 2026-05-04#algorithms#searching#binary-search#lookup#frontend

Coding Practice: Searching

Ten medium-level searching questions focused on binary search variants, lookup strategies, boundary conditions, and real UI data access patterns.

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:

  1. Binary Search Exact Match — build a reliable baseline.
  2. Find First Occurrence — left-bound variant.
  3. Find Last Occurrence — right-bound variant.
  4. Lower Bound — first index where value >= target.
  5. Upper Bound — first index where value > target.
  6. Search in Rotated Sorted Array — branch safely on sorted halves.
  7. Find Peak Element — search without full scan.
  8. Find Minimum in Rotated Array — handle shifted sorted structure.
  9. Closest Value to Target — compare neighbors after boundary search.
  10. 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: solve
Best 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