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

Popular posts from this blog

Discover the Best Steel Manufacturer: Adnan & Sons

Online Cabinets and Lockers in Pakistan: Discover Adnan & Sons' Top-Quality Steel Products

The Best Emergency Exit Door in Pakistan by Adnan & Sons