(int[] arr, int[][] mat)
| 1 | class Solution { |
| 2 | public int firstCompleteIndex(int[] arr, int[][] mat) { |
| 3 | int n = mat.length; //rows |
| 4 | int m = mat[0].length; //cols |
| 5 | int rowCount[] = new int[n]; |
| 6 | int colCount[] = new int[m]; |
| 7 | // num -> (r,c) |
| 8 | HashMap<Integer,int[]> map = new HashMap<>(); |
| 9 | for(int i=0;i<n;i++){ |
| 10 | for(int j=0;j<m;j++){ |
| 11 | map.put(mat[i][j], new int[]{i,j}); |
| 12 | } |
| 13 | } |
| 14 | int totalCells = n*m; |
| 15 | for(int i=0;i<totalCells;i++){ |
| 16 | int cell[] = map.get(arr[i]); |
| 17 | rowCount[cell[0]]++; |
| 18 | colCount[cell[1]]++; |
| 19 | if(rowCount[cell[0]] == m || colCount[cell[1]] == n){ |
| 20 | return i; |
| 21 | } |
| 22 | } |
| 23 | return -1; |
| 24 | } |
| 25 | } |
nothing calls this directly
no outgoing calls
no test coverage detected