Created
March 5, 2025 17:53
-
-
Save tatsuyax25/820c07b8b2029ddb1c96baa17e7f0cb4 to your computer and use it in GitHub Desktop.
There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes: At the first minute, color any arbitrary unit cell blue.
Every minute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} n | |
* @return {number} | |
*/ | |
var coloredCells = function(n) { | |
// This function calculates the number of blue cells in the grid after 'n' minutes. | |
// The formula is derived as the sum of two squares: | |
// (n * n) represents the number of cells in an n x n grid, which is the inner square. | |
// ((n - 1) * (n - 1)) represents the number of cells in an (n-1) x (n-1) grid, which is the outer ring. | |
return (n * n) + ((n - 1) * (n - 1)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment