Map solution for C# (explanation + complexity)
Approach\nThe problem can be divided into two sub-problems:\n1. How to find the value in the matrix in a fast way\n2. How to understand that a row or column is 
# Approach\nThe problem can be divided into two sub-problems:\n1. How to find the value in the matrix in a fast way\n2. How to understand that a row or column is completely painted\n\nSo,\n1. To solve the first problem, we will create a dictionary with cell values as a key and row/column indices as a value. It will cost us some space, but it allows us to get information about the cell for O(1) time.\n2. Create two arrays assigned for each rows/columns indices and  increase their values during traversal of the arr array.\n\nWhen we fill a row or column, we can return the result.\n\n# Complexity\n- Time complexity: O(m*n)\n- Space complexity: O(m*n)\n\n# Code\n```\npublic int FirstCompleteIndex(int[] arr, int[][] mat)\n{\n    var dict = new Dictionary<int, Tuple<int, int>>();\n\n    for (var i = 0; i < mat.Length; ++i)\n    {\n        for (var j = 0; j < mat[i].Length; ++j)\n        {\n            dict.Add(mat[i][j], new Tuple<int, int>(i, j));\n        }\n    }\n\n    if (dict.Count == 0)\n    {\n        return -1;\n    }\n\n    var rows = new int[mat.Length];\n    var cols = new int[mat[0].Length];\n\n    for (var i = 0; i < arr.Length; ++i)\n    {\n        var item = dict[arr[i]];\n\n        rows[item.Item1]++;\n        cols[item.Item2]++;\n        if (rows[item.Item1] == mat[0].Length || cols[item.Item2] == mat.Length)\n        {\n            return i;\n        }\n    }\n\n    return -1;\n}\n```
['C#']