The O(n) constraint is the whole point of the problem.
Start by clarifying the problem constraints and edge cases, then propose Quickselect with randomized pivot for average O(n) time. Explain the algorithm, analyze its complexity, and discuss trade-offs with alternatives like heap-based solutions.
Pro tip: Mention that Quickselect's worst-case O(n^2) can be mitigated with median-of-medians or random pivot, and that in practice, a heap is often preferred for streaming data or when k is small.
Confirm that the array is unsorted, k is 1-indexed, and duplicates count as separate elements. Ask about input size, memory constraints, and whether the array can be modified.
Select Quickselect for average O(n) time, or a min-heap of size k for O(n log k) time. Justify the choice based on constraints and expected input.
Describe partitioning around a random pivot, then recursively search only the side containing the kth largest. Emphasize that average time is O(n) due to halving the search space.
State average O(n) time and O(1) extra space for iterative Quickselect. Acknowledge worst-case O(n^2) and how randomization reduces its likelihood.
Compare with heap-based solution: O(n log k) time, O(k) space, better for streaming or when k is small. Mention that Quickselect modifies the array.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.