Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. function maxProfit(arr) {
  2.  
  3. var max = 0;
  4. var ops = 0;
  5.  
  6. for (let i=0; i < arr.length - 1; i++) {
  7. for (let j=i+1; j <= arr.length - 1; j++) {
  8. ops++;
  9. if (arr[j] - arr[i] > max) {
  10. max = arr[j] - arr[i];
  11. }
  12. }
  13. }
  14.  
  15. console.log(ops);
  16. return max;
  17.  
  18.  
  19. }
  20.  
  21. console.log(maxProfit([25, 3, 1, 29, 13, 8, 45, 2, 4, 9, 5, 7, 12, 19]));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement