Skip to content

Instantly share code, notes, and snippets.

@tatsuyax25
Created March 5, 2025 17:53
Show Gist options
  • Save tatsuyax25/820c07b8b2029ddb1c96baa17e7f0cb4 to your computer and use it in GitHub Desktop.
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
/**
* @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