#K54162. Maximum Profit in Stock Trading
Maximum Profit in Stock Trading
Maximum Profit in Stock Trading
This problem is a classic stock trading problem. Given a list of stock prices, your task is to determine the maximum profit that can be achieved by performing a single buy and a single sell transaction. Note that the stock must be bought before it is sold. The profit can be mathematically expressed as:
$$ profit = P_j - P_i \quad \text{for} \quad j > i $$If no profit is possible, the answer should be 0.
inputFormat
The input starts with an integer T denoting the number of test cases. Each test case consists of:
- An integer N representing the number of stock prices.
- N space-separated integers denoting the stock prices.
outputFormat
For each test case, output a single integer representing the maximum profit possible. Each output should be printed on a new line.
## sample2
7 100 180 260 310 40 535 695
5 190 180 170 160 150
655
0
</p>