FastPrepMinimum Server Vulnerability

Minimum Server Vulnerability

Cashfree Payments logoCashfree Payments● MediumFULLTIMEOA
Learn

Problem statement

You are given an array of positive integers vulnerability. Choose exactly k server positions so that no two chosen positions are adjacent.

The vulnerability of a selection is the maximum value among its chosen servers. Return the minimum possible vulnerability of any valid selection.

Function

getMinVulnerability(vulnerability: int[], k: int) → int

Examples

Example 1

vulnerability = [2,3,5,9]k = 2return = 5

The valid pairs shown by the source are [2,5], [3,9], and [2,9]. Their maximum values are 5, 9, and 9, so the minimum possible vulnerability is 5.

Example 2

vulnerability = [2,4,6,8,10]k = 2return = 6

Choosing positions 0 and 2 gives vulnerability 6. Any valid pair with a smaller maximum would need two non-adjacent values from 2 and 4, but those positions are adjacent.

Constraints

  • 1 <= vulnerability.length <= 10^5.
  • 1 <= vulnerability[i] <= 10^9.
  • 1 <= k <= (vulnerability.length + 1) / 2.

More Cashfree Payments problems

See Cashfree Payments hiring insights
public int getMinVulnerability(int[] vulnerability, int k) {
    // Write your code here.
}
vulnerability[2,3,5,9]
k2
expected5
Checking account…