#3128
Right Triangles
medium · 48.4% accepted · 133 likes · top 34%
array · hash table · math · combinatorics · counting
Description
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.
Solution