As reported: DocuSign software engineering intern online assessment (April 2025), question 3 of 3: given a list of integers
vulnerability(a score per server) and an integerk, select exactlyknon-adjacent servers so that the maximum vulnerability among the selected servers is minimised; return that minimum possible maximum.
This is LeetCode 2560 — House Robber IV, with servers as houses.
Servers stand in a row; nums[i] is the vulnerability score of server i. Select k servers, no two of them adjacent. The risk of a selection is the largest score among the selected servers. Return the minimum possible risk.
Example 1
nums = [2,3,5,9], k = 2 -> 5
Selections of two non-adjacent servers: {2, 5} → risk 5, {2, 9} → 9, {3, 9} → 9. The best is 5.
Example 2
nums = [2,7,9,3,1], k = 2 -> 2
Select {2, 1} (servers 0 and 4): risk 2.
Clarifications
- It is always possible to select
knon-adjacent servers. - If a risk
rallows selecting more thankservers, it also allows exactlyk(drop some), so "at leastk" and "exactlyk" have the same answer.
Constraints: 1 ≤ nums.length ≤ 10^5; 1 ≤ nums[i] ≤ 10^9; 1 ≤ k ≤ (nums.length + 1) / 2.
Code runner format: two lines — nums, then k (LeetCode's test-case format). Implement minCapability(nums, k); the harness prints the answer.