-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19th July 2024.java
More file actions
31 lines (30 loc) · 923 Bytes
/
19th July 2024.java
File metadata and controls
31 lines (30 loc) · 923 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
class Solution {
public List<Integer> luckyNumbers (int[][] mat) {
Map<Integer,Integer> helper = new HashMap<>();
for(int i=0;i<mat.length;i++){
int min = Integer.MAX_VALUE;
int col = 0;
for(int j=0;j<mat[0].length;j++){
if(mat[i][j] < min){
min = mat[i][j];
col = j;
}
}
helper.put(min,col);
}
List<Integer> ans = new ArrayList<>();
for(Map.Entry<Integer,Integer> m : helper.entrySet()){
int el = m.getKey();
int col = m.getValue();
boolean flag = true;
for(int i=0;i<mat.length;i++){
if(mat[i][col] > el){
flag = false;
break;
}
}
if(flag) ans.add(el);
}
return ans;
}
}