Skip to content

Commit

Permalink
Time: 24 ms (62.19%), Space: 65.8 MB (64.18%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Jan 20, 2025
1 parent 6691cf2 commit 0d0a8a3
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public int firstCompleteIndex(int[] arr, int[][] mat) {
HashMap<Integer, int[]> map = new HashMap<>();
int row[] = new int[mat.length];
int col[] = new int[mat[0].length];

for (int i = 0; i < mat.length; i++) {
for (int j = 0; j < mat[0].length; j++) {
int coords[] = new int[2];
coords[0] = i;
coords[1] = j;
map.put(mat[i][j], coords);
}
}

for (int i = 0; i < arr.length; i++) {
int coords[] = map.get(arr[i]);
int r = coords[0];
int c = coords[1];

row[r]++;
col[c]++;

if (row[r] == mat[0].length || col[c] == mat.length) return i;
}

return 1;
}
}

0 comments on commit 0d0a8a3

Please sign in to comment.