Minimize the largest selected value across nonadjacent positions

Quick 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.

Minimize the largest selected value across nonadjacent positions

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Online Assessment

Given an array of positive integers and an integer k, select at least k positions such that no two selected positions are adjacent. The cost of a selection is the largest selected value. Return the smallest achievable cost. ### Function Signature ```python def minimum_selection_cost(values: list[int], k: int) -> int: ``` ### Rules - Positions i and i + 1 cannot both be selected. - The original order cannot be changed. - Return only the minimum cost, not the selected positions. ### Constraints These bounds define this practice version. - `1 <= len(values) <= 100000`. - `1 <= values[i] <= 1000000000`, within signed 32-bit range. - `1 <= k <= (len(values) + 1) // 2`, so a selection exists. ### Examples ```text Input: values = [2, 3, 5, 9], k = 2 Output: 5 ``` Selecting indices 0 and 2 has cost 5. A smaller threshold cannot supply two nonadjacent positions. ```text Input: values = [4, 1, 7], k = 1 Output: 1 ``` Select only the middle position.

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

Microsoft logo
Microsoft
Nov 16, 2026
mediumSoftware EngineerOnline AssessmentCoding & Algorithms
0
0

Given an array of positive integers and an integer k, select at least k positions such that no two selected positions are adjacent. The cost of a selection is the largest selected value. Return the smallest achievable cost.

Function Signature

def minimum_selection_cost(values: list[int], k: int) -> int:

Rules

  • Positions i and i + 1 cannot both be selected.
  • The original order cannot be changed.
  • Return only the minimum cost, not the selected positions.

Constraints

These bounds define this practice version.

  • 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: values = [2, 3, 5, 9], k = 2
Output: 5

Selecting indices 0 and 2 has cost 5. A smaller threshold cannot supply two nonadjacent positions.

Input: values = [4, 1, 7], k = 1
Output: 1

Select only the middle position.