O(N^3) solution for 50x50 matrix
In this problem we need to not only traverse the matrix, but also each diagonal, bringing the total complexity to N^3 or 125K iterations... code is below, cheers, ACC Difference of Number of Distinct Values on Diagonals - LeetCode 2711. Difference of Number of Distinct Values on Diagonals Medium 53 125 Add to List Share Given a 0-indexed 2D grid of size m x n , you should find the matrix answer of size m x n . The value of each cell (r, c) of the matrix answer is calculated in the following way: Let topLeft[r][c] be the number of distinct values in the top-left diagonal of the cell (r, c) in the matrix grid . Let bottomRight[r][c] be the number of distinct values in the bottom-right diagonal of the cell (r, c) in the matrix grid . Then answer[r][c] = |topLeft[r][c] - bottomRight[r][c]| . Return the matrix answ...