You are given an Array of stocks denoting profits which you can get on day 1 by selling them, is of n size, and a query array. You have return array of size query.length, where ith value denotes no. of ways in which you can choose all the values from profit array where the acquired totalprofit is >= query[i];
On day1 if you choose some value, you will get full amount, day 2 the profit will divided by 2 , day 3 it will divided by 4 and so on while doing half only integer value will count;
TestCase -
Stocks Profit on Day 1 — [10, 5] Query — [10, 12, 15]
ansArray = [2, 1, 0]; ansArray[0] = 2, because we can choose values in 2 ways first choose 10 on day1, and then 5 on day2, so 10 + 5/2 = 10 + 2 >= 10 second choose 5 on day1, and then 10 on day 2, so 5 + 10/2 = 5 + 5 >= 10
ansArray[1] = 1 because there is only one way to choose choose 10 on day1 and then 5 on day 2, so 10 + 5/2 = 10 + 2 >= 12 5 and 10/2 wont work here; similarly ansArray[2] = 0;
If someone can give some solution to this problem it will really help me I am thinking about this from about 2 days and not able to come up to a satisfactory solution. Any help is appreciated.