Java | Simple solution
Complexity\n- Time complexity: O(mn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(mn)\n Add your space complexity here, e.g. O(n) \n\n# 
# Complexity\n- Time complexity: $$O(m*n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m*n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public int firstCompleteIndex(int[] arr, int[][] mat) {\n    var m = mat.length;\n    var n = mat[0].length;\n    \n    var rows = new int[m];\n    var cols = new int[n];\n    \n    var map = new int[m*n][2];\n    \n    for (var i=0; i<m; i++) {\n      for (var j=0; j<n; j++) {\n        var a = mat[i][j] - 1;\n\n        map[a][0] = i;\n        map[a][1] = j;\n      }\n    }\n    for (var i=0; i < arr.length; i++) {\n      var a = arr[i] - 1;\n\n      rows[map[a][0]]++;\n      cols[map[a][1]]++;\n      \n      if (rows[map[a][0]] == n || cols[map[a][1]] == m)\n        return i;\n    }    \n    return m*n;\n  }\n}\n```\nIf you like my solution, please upvote it!
['Java']