We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ac4ffe8 commit 19f2f4cCopy full SHA for 19f2f4c
Hard/StockPicker.java
@@ -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