Create Stock trading

 nagarro-interview-questions
0
of 0 votes
1
Answer

Suppose you are a stock trader and you can do as many trades but if you stop you can't do another trade. You can start with any trade. Given an array of profits/loss of trades and find the maximum profit you can make.

Input:
Number of trades
Profit/loss in each trade

Output:
Max Profit

Ex:

Input:

7 
1 2 3 4 -2 -3 1

Output:

10

Explaination: Trade of [1,2,3,4]

Input:

5
-2 -3 -4 1 2

Output:

3