Find Kth Minimum Vulnerability
Updated
Problem statement
A service has n servers in a row, where vulnerability[i] is the vulnerability score of the server at index i.
A client chooses a contiguous group of exactly m servers. The vulnerability of that group is its kth minimum value: sort the group's scores in non-decreasing order and take the value at one-based position k. Repeated scores occupy separate positions.
Find this vulnerability for every possible group of m contiguous servers. Return the values in left-to-right window order.
Function
findKthMinimumVulnerability(k: int, m: int, vulnerability: int[]) → int[]Examples
Example 1
k = 2m = 3vulnerability = [1, 3, 2, 1]return = [2, 2]The two length-3 groups are [1, 3, 2] and [3, 2, 1]. Each group sorts to [1, 2, 3], whose second minimum is 2. Therefore, return [2, 2].
Example 2
k = 3m = 4vulnerability = [4, 2, 3, 1, 1]return = [3, 2]The groups are [4, 2, 3, 1] and [2, 3, 1, 1]. They sort to [1, 2, 3, 4] and [1, 1, 2, 3], whose third minimum values are 3 and 2. Therefore, return [3, 2].
Constraints
1 ≤ k ≤ m ≤ n ≤ 3 × 1051 ≤ vulnerability[i] ≤ 109
More Amazon interview questions
- Lexicographically Largest IdentifierOA · Seen Nov 2026
- Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
- Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fill One Exact-Length Binary WindowOA · Seen Nov 2026
Similar questions at other companies
- Auction Sniping Window MinimumCisco · OACisco interview questions
- Choose One from Each Set to Minimize the RangeInMobi · OAInMobi interview questions
- Sliding Window Average Excluding the Largest K ValuesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Sliding Window MedianNotion · ONSITE INTERVIEWNotion interview questions
- Sliding Window MedianBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
- Split Tender Part 2 - Expiration DatesStripe · OAStripe interview questions
- Organization Reputation After Employee DeparturesHSBC · OAHSBC interview questions