You are given an integer
n
. Consider an equilateral triangle of side lengthn
, broken up inton2
unit equilateral triangles. The triangle hasn
ith
row has2i - 1
unit equilateral triangles.The triangles in the
ith``(i, 1)
to(i, 2i - 1)
. The following image shows a triangle of side length4
with the indexing of its triangle.Two triangles are neighbors if they share a side. For example:
- Triangles
(1,1)
and(2,2)
are neighbors- Triangles
(3,2)
and(3,3)
are neighbors.- Triangles
(2,2)
and(3,3)
are not neighbors because they do not share any side.
1 >k
- If there is no such triangle, stop the algorithm.
- Color that triangle red.
- Go to step 1.
Choose the minimum
k
possible and setk
triangles red before running this algorithm such that after the algorithm stops, all unit triangles are colored red.Return a 2D list of the coordinates of the triangles that you will color red initially. The answer has to be of the smallest size possible. If there are multiple valid solutions, return any.
1 | class Solution { |