Problem of the day
Input: ‘N’ = 7, ‘PRICES’ = [100, 80, 60, 70, 60, 75, 85]
Output: [1, 1, 1, 2, 1, 4, 6]
On the sixth day, when the stock price was 75, the span came out to be 4 because the last three prices(plus today) were less than the current or the sixth day's price. Similarly, we can deduce the remaining results.
The first line will contain the integer 'T,' denoting the number of test cases.
The first line of each test case contains an integer ‘N’ denoting the number of days.
The second line of each test case contains ‘N’ integers denoting the prices of the stocks.
For each test case, return an array that contains the stock’s span for each day.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^5
1 <= A[i] <= 10^9
Sum of ‘N’ <= 10^5
Time Limit: 1 sec
2
4
2 1 2 4
2
1 2
1 1 2 4
1 2
For the first case:
Number of consecutive days with price smaller than 0th day(starting from 0th day) = 1
Number of consecutive days with price smaller than 1st day(starting from 1st day) = 1
Number of consecutive days with price smaller than 2nd day(starting from 2nd day) = 2
Number of consecutive days with price smaller than 3rd day(starting from 3rd day) = 4
For the second case:
Number of consecutive days with price smaller than 0th day(starting from 0th day) = 1
Number of consecutive days with price smaller than 1st day(starting from 1st day) = 2
2
6
20 12 1 28 16 20
5
2 14 29 21 11
1 1 1 4 1 2
1 2 3 1 1