Array Search, Selection, And Dynamic Programming
Asked of: Software Engineer
Last updated

What's being tested
Array search, selection, and dynamic programming problems test whether you can turn brute-force scans into structured O(log n), O(n), or O(n log n) solutions. Interviewers look for clean boundary handling, invariant-based reasoning, and the ability to explain time/space tradeoffs under production-like constraints.
Patterns & templates
-
Binary search boundaries — implement
lower_bound(nums, target)andupper_bound(nums, target);O(log n)time, avoid off-by-one errors. -
Quickselect partitioning — find kth largest via in-place
partition; averageO(n), worstO(n^2), randomized pivot reduces risk. -
Heap selection — maintain a min-heap of size
k;O(n log k)time, safer than Quickselect when worst-case predictability matters. -
Dynamic programming for subsequences — LIS uses
dp[i] = max(dp[j] + 1)forj < i;O(n^2)baseline, simple and explainable. -
Patience sorting LIS — maintain
tailsand binary-search replacement index;O(n log n)time, buttailsis not the actual subsequence. -
Prefix/suffix parity sums — deletion-fairness problems need even/odd sums before and after index removal;
O(n)time,O(1)possible. -
Interval sweep / min-heap rooms — sort start times or intervals; count overlapping meetings in
O(n log n), clarify inclusive vs exclusive endpoints.
Common pitfalls
Pitfall: Returning any target index instead of the first/last boundary misses the core binary search invariant.
Pitfall: Treating kth largest as index
kafter sorting; it is usuallynums[len(nums) - k]in ascending order.
Pitfall: For LIS, using
<=instead of<changes “increasing” into “non-decreasing.”
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
- Compute length of longest increasing subsequenceTikTok · Software Engineer · Technical Screen · medium
- Find kth smallest in sorted 2D matrixTikTok · Software Engineer · Technical Screen · medium
- Find k-th largest element in arrayTikTok · Software Engineer · Technical Screen · medium
- Find first and last index of targetTikTok · Software Engineer · Technical Screen · easy
- Maximize min+max of contiguous subarrayTikTok · Software Engineer · Technical Screen · medium
- Find >n/3 elements in sorted arrayTikTok · Software Engineer · Technical Screen · Medium
- Compute rooms and verify tree completenessTikTok · Software Engineer · Technical Screen · Medium
- Find >n/3 elements in sorted arrayTikTok · Software Engineer · Technical Screen · Medium
- Solve grid min path and sqrt by binary searchTikTok · Software Engineer · Technical Screen · Medium
- Count deletions making array fairTikTok · Software Engineer · Technical Screen · Medium
- Solve intervals and distinct islandsTikTok · Software Engineer · Onsite · Medium
- Solve top-K and string rotation matchTikTok · Software Engineer · Technical Screen · Medium
Related concepts
- Binary Search, Partitioning, And Convex SearchCoding & Algorithms
- Arrays, Intervals, Sliding Windows, And Prefix SumsCoding & Algorithms
- Core Data Structures, Algorithms, And ComplexityCoding & Algorithms
- Binary Search And Feasibility OptimizationCoding & Algorithms
- Top-K, Heaps, Quickselect, And Frequency AnalysisCoding & Algorithms
- Heaps And Selection AlgorithmsCoding & Algorithms