Minimize the largest selected value across nonadjacent positions
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: Choose at least k nonadjacent array positions while minimizing the largest selected value. Preserve original adjacency and reason about threshold feasibility, greedy selection, and cases where eligible positions cluster.
Read the full Microsoft Software Engineer interview experience this question came from
Constraints
- `1 <= len(values) <= 100000`.
- `1 <= values[i] <= 1000000000`, within signed 32-bit range.
- `1 <= k <= (len(values) + 1) // 2`, so a selection exists.
Examples
Input: ([2, 3, 5, 9], 2)
Expected Output: 5
Explanation: Two nonadjacent positions become feasible at threshold five.
Input: ([4, 1, 7], 1)
Expected Output: 1
Explanation: The minimum value is enough for one selection.
Hints
- For a fixed proposed cost, consider only positions whose values do not exceed it.
- If a cost is feasible, every larger proposed cost is feasible as well.