Practice Right Triangles
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a 2D boolean matrix grid. A collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements may not be next to each other. Return an integer that is the number of right triangles that can be made with 3 elements of grid such that all of them have a value of 1.
Source: Right Triangles on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[0,1,0],[0,1,1],[0,1,0]]
2
# Example 2
grid = [[1,0,0,0],[0,1,0,1],[1,0,0,0]]
0
# Example 3
grid = [[1,0,1],[1,0,0],[1,0,0]]
2
Constraints
Related LeetCode Problems
Practice more problems similar to Right Triangles.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.