Color the Triangle Red - Problem

Imagine you're a digital artist working with a beautiful equilateral triangle canvas made up of smaller triangular tiles. Your goal is to create a "viral coloring effect" where red color spreads automatically across the entire triangle!

The Setup: You have an equilateral triangle of side length n, divided into nยฒ unit triangular tiles. The triangle has n rows, where row i contains 2i - 1 triangles, indexed as (i, 1) to (i, 2i - 1).

The Magic Rule: Once you initially color k triangles red, an automatic spreading algorithm runs:

  • ๐Ÿ” Find any white triangle that has at least 2 red neighbors
  • ๐ŸŽจ Color it red
  • ๐Ÿ”„ Repeat until no more triangles can be colored

Your Mission: Find the minimum number of triangles to color initially so that the spreading algorithm eventually colors the entire triangle red. Return the coordinates of these initial triangles.

Note: Two triangles are neighbors if they share a side. For example, (1,1) and (2,2) are neighbors, but (2,2) and (3,3) are not.

Input & Output

Constraints

Asked in
25.0K Views
Medium Frequency
~15 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen