best time to sell stock
package com.company;
import java.util.*;
public class Main {
public static void main(String[] args) {
// best time to buy and sell stocks
int arr[]={7,1,5,4,3};
int profit =0;
int minimum=Integer.MAX_VALUE;
for(int i=0;i<arr.length;i++) {
if (arr[i]<minimum) {
minimum=arr[i];
}
else if(arr[i]-minimum>profit) {
profit=arr[i]-minimum;
}
}
System.out.println(profit);
}
}
Comments
Post a Comment