DOCUSIGN Coding Question – Solved

8 Live
Hackerrank developers want to deploy an application on a set of exactly k servers with different vulnerabilities. They have an option to choose the k servers from a sequence of n servers where vulnerability[i] represents the vulnerability of the ith server. The vulnerability of the chosen k servers is defined as the maximum vulnerability amongst any of the chosen servers. To avoid congestion, they would like to choose a subsequence of k servers such that no two adjacent servers are chosen as part of the k servers. Given an array vulnerability and an integer k, find the minimum possible vulnerability of the chosen servers such that the above condition is respected. Example Given n = 4, k = 2 and vulnerability = [2, 3, 5, 9], only 3 subsequences of k = 2 non-adjacent servers exist: [2, 5] - max = 5 [3, 9] - max = 9 [2, 9] - max = 9 Report 5 as the answer. Function Description Complete the function getMinVulnerability in the editor below. getMinVulnerability has the following parameters: int vulnerability[n]: An array of integers int k: the length of the subsequences to form Returns int: the minimum value returned by the max function for all valid subsequences Constraints 1 <= n <= 10^5 1 <= k <= (n + 1) / 2

Asked in: DOCUSIGN

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |