Skip to content

Commit 19f2f4c

Browse files
authored
Create StockPicker.java
1 parent ac4ffe8 commit 19f2f4c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Hard/StockPicker.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Main {
5+
6+
public static int StockPicker(int[] arr) {
7+
// code goes here
8+
int result=0;
9+
10+
for ( int i = 0 ; i<arr.length-1 ; i++){
11+
for (int j =i+1 ; j<arr.length; j++){
12+
13+
if (arr[i]<arr[j]) if ( arr[j]-arr[i] > result) result = arr[j]-arr[i];
14+
}
15+
16+
}
17+
return result == 0 ? -1 : result;
18+
}
19+
20+
public static void main (String[] args) {
21+
// keep this function call here
22+
Scanner s = new Scanner(System.in);
23+
System.out.print(StockPicker(s.nextLine()));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)