Plz help me in this prob Nasdaq hiring challenge ..how to approach?

one simple solution is:
sort the array.
then,just add numbers from the end of array at indexes which are multiples of 3.
e.g.
1,2,3,4,5,6,7,8
Now,answer=6+3=9
as on 1st day,1,6,7,8 and on 2nd day 2,3,4,5.

1 Like

Since you are required to maximize the second min element, first sort the array in descending and simply add the elements in the indices: 2,5,8,11 .

Code for your reference
int findSum(int A[], int n){
       int sum = 0;
      sort(A,A+N, greater<int>());
      for(int i = 0; i<N-N/4;i++){
              sum = (sum+A[i])%mod;  
      }
      return sum;

Can you please post the second question too ?
I would like to know the solution for 2nd one as I was not able to solve it during the contest

The second question was given a binary string : consisting of only zeroes and ones
At each step we can remove alternating subsequence from the string
Alternating subsequence is defined as “01010…” , “101…” , “01…” , “10…”
Note that “100” and “0111” are not alternating subsequences.
We have to minimize the number of steps to reduce the binray string to empty string.

Test Case : " 0100100111"
Output : 3

See this question https://codeforces.com/contest/1440/problem/B , Just put n=4 here :smiley:

1 Like