-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinMaxInArray.java
More file actions
45 lines (37 loc) · 905 Bytes
/
MinMaxInArray.java
File metadata and controls
45 lines (37 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class MinMaxInArray {
public Pair<Integer, Integer> getMinMax(int[] arr) {
// Code Here
int min=0;
int max=0;
for(int i=0; i<arr.length;i++){
int val = arr[i];
if(val < min || min == 0){
min = val;
}
if(val > max){
max = val;
}
}
return new Pair<Integer, Integer>(min,max);
}
}
// User function Template for Java
// User function Template for Java
class Pair<K, V> {
private final K key;
private final V value;
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return key;
}
public V getValue() {
return value;
}
}
/*
Java users need to return result in Pair class
For Example -> return new Pair(minimum,maximum)
*/