Traverse and keep adding the profit until a day with price of stock higher than currentDay is obtained
while ( day >= 0 && ( prices [ currentDay ] > prices [ day ] ) ) { profit += ( prices [ currentDay ] - prices [ day ] ) ; day -- ; }