1053. Minimum Initial Red Triangles

You are given an integer n representing the side length of an equilateral triangle that is divided into n² unit triangles arranged in n rows (1-indexed). The i-th row contains 2i - 1 triangles, labeled with coordinates from (i, 1) to (i, 2i - 1). Two triangles are neighbors if they share a side. Choose the minimum set of triangles to initially color red such that, when you repeatedly color any white triangle with at least two red neighbors, eventually all triangles become red.

Return the coordinates of the initially chosen red triangles (any valid solution will do).

Example 1:

Input : n = 1

Output : [[1, 1]]

Explanation:

The triangle has only one unit triangle. Coloring it red initially ensures all are red.

Now Your Turn!

Pick the correct output for the given input

Input : n = 4

Output : [[1,1], [2,1], [2,3], [3,1], [3,5], [4,1], [4,7]]

Explanation:

The leftmost and rightmost triangles of each row are chosen. The algorithm propagates red coloring inward until the entire triangle is covered.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

1 ≤ n ≤ 1000

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<vector<int>> colorRed(int n) {
// Your Code goes here
}
};
Test Case

Input:

N