House Robber IV
Real-world version: Smallest Ceiling for k Non-Neighbouring PicksThe statement here is our own: the same inputs, outputs and technique.
Readings are given as nums. A pick takes at least k of them, and no two picked readings may sit next to each other in the list.
A pick's ceiling is the largest reading it takes. Return the smallest ceiling any pick can have.
Examples
Example 1
- Input
- nums = [14, 3, 27, 9, 41, 6], k = 2
- Output
- 6
The readings 3 and 6 sit at positions 1 and 5, so they are not next to each other, and taking them gives a ceiling of 6. A ceiling of 3 leaves only the single reading 3 available, which is one short of the two wanted.
Example 2
- Input
- nums = [1000000000, 1, 1000000000], k = 2
- Output
- 1000000000
Two readings must be taken and the only non-neighbouring pair is the two ends, both a billion.
Example 3
- Input
- nums = [1, 1, 1, 1, 1], k = 3
- Output
- 1
Every reading is 1, and three can be taken at positions 0, 2 and 4.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
- 1 <= k <= (nums.length + 1) / 2
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def min_capability(nums: list[int], k: int) -> int:public int minCapability(int[] nums, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Minimize the Maximum Difference of PairsReal-world version: Pairing Gears by Closest Tooth CountMedium
- Split Array Largest SumReal-world version: Balanced TruckloadsHard
- Path Existence Queries in a Graph IIReal-world version: Relay Hops Across The Field NetworkHard
- Earliest Finish Time for Land and Water Rides IReal-world version: Forge and Kiln BookingEasy