Skip to main content
Back to problems
Leetcode
Medium
Arrays
Binary Search
Greedy
Google
House Robber IV

Choose at least kk non-adjacent houses to rob while minimizing the maximum money taken from any robbed house.

Acceptance 0%
Problem Statement

You are given an array of integers representing the money in each house arranged in a line, and an integer kk. You want to rob exactly kk houses such that no two robbed houses are adjacent.

For any valid selection, define its capability as the maximum amount of money in any robbed house.

Your task is to find the minimum possible capability among all valid selections of exactly kk non-adjacent houses.

If no valid selection exists, the problem is typically treated as having no feasible answer, but the intended challenge assumes the input allows a solution.

Input Format

  • An integer array nums where nums[i] is the money in the ii-th house.
  • An integer k, the number of houses to rob.

The houses are in a straight line, so adjacent indices cannot both be chosen.

Output Format

  • Return the minimum possible capability of a valid selection of exactly k houses.

Constraints

  • Houses are arranged in a line.
  • Chosen houses must be non-adjacent.
  • Exactly k houses must be selected.
  • The optimal value is determined by minimizing the maximum robbed value among the selected houses.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [2,3,5,9], k = 2

Output

5

Explanation

With capability 4, you can only take one house with value at most 4. With capability 5, you can take houses 0 and 2 with values 2 and 5, which are non-adjacent. So the minimum possible capability is 5.

Example 2

Input

nums = [2,7,9,3,1], k = 2

Output

2

Explanation

Choose houses with values 2 and 1. They are not adjacent, and the capability is max(2, 1) = 2, which is optimal.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.