Time: 30 min
Platform: Hackerrank
Statement 1: Given an array arr
of size n
, you have to apply the following operation(s): Take a subarray of size k
. If this subarray is odd, you have to choose the minimum element in it and if the subarray is odd, you have to choose the maximum element (i.e., subarray 0123....k-1 is the first odd subarray and 123...k is the first even subarray and so on). Apply the same operations on this array of selected numbers until a single element is left.
ex: arr = {9,10,19,14,11}
and k=3
After first operation, arr = {9,19,11}
Then arr={9}
Constraints: n<=1e5
Statement 2: There are n
students, each needing arr[i]
for a project they are going to make. They are paired into m
inclusive-pairs (a student may appear in more than a single pair). You are the VP of a startup and you have to fund these pairs. There are q
queries and you have to answer the maximum number of students you can fund with the amount q[j]
. If a student has been previously recieved funds as part of another pair, they won't be funded again.