All problems
0987MediumArrayBinary SearchDynamic ProgrammingGreedy

Smallest Ceiling for k Non-Neighbouring Picks

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2560House Robber IV

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def min_capability(nums: list[int], k: int) -> int:
Java
public int minCapability(int[] nums, int k)
September 7
Apply