#K40342. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
Given the stock prices for consecutive days, your task is to compute the maximum profit achievable by buying and selling the stock exactly once. If no profit can be made, return 0. Formally, given a sequence of prices \( P_1, P_2, \dots, P_n \), find the maximum value of \( P_i - P_j \) for \( i > j \). If \( P_i \leq P_j \) for all \( i > j \), then the profit is 0.
inputFormat
The first line of input contains an integer T representing the number of test cases. Each of the next T lines contains a test case: a space-separated list of integers representing the stock prices on consecutive days.
outputFormat
For each test case, output a single line containing the maximum profit achievable by buying and selling the stock exactly once. If no profit is possible, output 0.
The profit is computed as \( \max_{j < i} (price_i - price_j) \).
## sample3
7 1 5 3 6 4
7 6 4 3 1
1 2 90 10
5
0
89
</p>