Advertisement
DiManco

MaxProfit

Sep 22nd, 2020
2,448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getProfit(list: number[]): number {
  2.   const maxProfitForEach: number[] = [];
  3.  
  4.   list.forEach((cost: number, index: number) => {
  5.     const nextDays = list.slice(index);
  6.     const maxCost = Math.max.apply(null, nextDays);
  7.    
  8.     maxProfitForEach.push(maxCost - cost);
  9.   });
  10.  
  11.   return Math.max.apply(null, maxProfitForEach);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement