Predict Answer
In this stock price prediction game launched on Amazon Games, Player 1 provides Player 2 with stock market data for n consecutive days, representing Amazon's stock prices on each day, represented by stockData[].
The rules of the game are as follows:
i (where 1 ≤ i ≤ n)j (1 <= j < i or i < j <= n) in the past or future, on which the stock price was lower than on the given day, i.e., stockData[j] < stockData[i]j which satisfies Rule 2, then Player 2 will find the day number which is smaller. (i.e. the smallest j satisfying Rule 2)j exists, then answer for that case is -1
Given q queries in the array queries, the task is to find the answer for each queries[i] in the queries and return a list of answer as per the above rules corresponding to each query.
Note: The description and the answer format both adhere to 1-based indexing for the arrays. (Please see the below Example for better understanding :)
Complete the function predictAnswer in the editor.
predictAnswer has 2 parameters:
int stockData[n]: an integer array denoting the value of each stockData[i] is the stock price on the i-th day (where0 ≤ i < n)int queries[q]: an integer array denoting the value of each element queries[i] is the day number given in the query (where0 ≤ i < q)
Returns
int[]: an integer array denoting the value at each index i is the answer to queries[i]
Thank you soooo much for sharing the source! All the credit goes to our incredible friend who made it possible! You’re the real MVP! 👑
1Example 1

Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 10^51 ≤ stockData[i] ≤ 10^91 ≤ q ≤ 10^51 ≤ queries[j] ≤ n