Minimum Server Vulnerability
Updated
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) → intExamples
Example 1
vulnerability = [2,3,5,9]k = 2return = 5The valid pairs 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 = 6Choosing 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 interview questions
Similar questions at other companies
- Minimum Non-Adjacent Selection CapabilityMicrosoft · OAMicrosoft interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum Robot and Human Fulfillment TimeAmazon · OA
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Array NullificationQRT · OA
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
- Three-Part Partition with Minimum Largest RangeLSEG · OALSEG interview questions
- K-Means ClusteringAtlassian · OAAtlassian interview questions
- Get Minimum Development TimeSalesforce · OASalesforce interview questions
- Job ExecutionMathWorks · OAMathWorks interview questions