
Input: 'X' = 2, 'Y' = 3, 'N' = 4, A = [2.0, 4.0, 3.0, 2.0]
Output: "1"
As moving average of length ‘2’ till index ‘2’ is ‘((4.0+3.5)/2)’=’3.5’, and the moving average of length ‘3’ till index ‘2’ is ‘((2.0+4.0+3.0)/3)’=’3.0’. As we move to the next index ‘3’, the moving average of length ‘2’ becomes ‘2.5’ and of length ‘3’ becomes ‘3.0’. So moving average to length ‘2’ changed smaller at current index from bigger at last index from moving average of length ‘3’, so they are cutting each other between this period.
The first line will contain the integer 'T', denoting the number of test cases.
For each test case, the first line contains two space-separated integers which are the moving average days ‘X’ and ‘Y’.
Second-line contains an integer ‘N’ denoting the number of stock prices.
The third line contains ‘N’ space-separated decimal values denoting the closing price of the stock for ‘N’ days.
For each test case, print the number of times the stock will give an uptrend or downtrend.
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 <= 'X', ‘Y’ <= 10^5
1.0 <= ‘A[i]’ <= 10^4
Time Limit: 1 sec
We will maintain the ‘X’ size and ‘Y’ size moving average. Now we will iterate over each ‘I’ ranging from max( ‘X’, ‘Y’ ) to ’ N’. For each ‘I’, compare the value of moving averages at the current index with the previous index. If ‘X’ size moving average was smaller than the ‘Y’ size moving average at the previous index but at the current index if ‘X’ size moving average is greater than ‘Y’ size moving average or vice-versa. It means that there is an intersection between their curves. Or there is an uptrend or downtrend.