Skip to content

Instantly share code, notes, and snippets.

@MohamedAbdelrazek
Last active September 27, 2017 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MohamedAbdelrazek/30713de89bfb8c658b9300ea44b6e7e5 to your computer and use it in GitHub Desktop.
Save MohamedAbdelrazek/30713de89bfb8c658b9300ea44b6e7e5 to your computer and use it in GitHub Desktop.
Mercury Engineering and Consultation Task
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
import java.util.ArrayList;
/**
*
* @author Mohamed AbdelraZek
*/
public class task {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
// Try any sequence b2a ;)
list.add(140);
list.add(345);
list.add(160);
list.add(24);
list.add(200);
list.add(11);
list.add(200);
showResut(list);
}
public static void showResut(ArrayList<Integer> list) {
int diff = 0;
int min = 0;
int max = 0;
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < list.size(); j++) {
if ((list.get(j) - list.get(i)) > diff) {
diff = (list.get(j) - list.get(i));
if (i < j) {
min = list.get(i);
max = list.get(j);
}
}
}
}
System.out.println("You should buy with " + min + "$ and sell with " + max + "$");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment