Practice Difference of Number of Distinct Values on Diagonals
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Difference of Number of Distinct Values on Diagonals
Problem Statement
For each cell (r, c) in grid, count the distinct values strictly above-left on its diagonal, and separately count the distinct values strictly below-right on that diagonal. Exclude the cell itself from both counts. Set answer[r][c] to the absolute difference of these counts and return answer.
Source: Difference of Number of Distinct Values on Diagonals on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[1,2,3],[3,1,5],[3,2,1]]
[[1,1,0],[1,0,1],[0,1,1]]
# Example 2
grid = [[1]]
[[0]]
Constraints
Related LeetCode Problems
Practice more problems similar to Difference of Number of Distinct Values on Diagonals.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.