2579. Count Total Number of Colored Cells
MediumView on LeetCode
Time: O(1)
Space: O(1)
Advertisement
Intuition
Count beautiful arrangements in grid: rows with same count of colored cells and same value modulo k.
Algorithm
- 1Iterate: count cells colored, track pattern. Combinatorial counting.
Common Pitfalls
- •Group by (count mod k). Each group of size g contributes floor(g/2) pairs.
2579.cs
C#
// Approach: After n minutes the colored diamond has n² + (n-1)² cells.
// Time: O(1) Space: O(1)
public class Solution
{
public long ColoredCells(int n)
{
return 1L * n * n + 1L * (n - 1) * (n - 1);
}
}Advertisement
Was this solution helpful?