aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-03-04 21:17:37 -0700
committerJack Sangdahl <[email protected]>2025-03-04 21:17:37 -0700
commit744f3716db1a2504b730a3f412be1b0516f61450 (patch)
treef8d5d7491eba341c915bf9a5a692e695e6c6c21d
parentd84519d4d115251af42c780c825447d1a7559868 (diff)
downloadleetcode-744f3716db1a2504b730a3f412be1b0516f61450.tar.gz
leetcode-744f3716db1a2504b730a3f412be1b0516f61450.zip
2579. count total number of coloured cells
-rw-r--r--count_total_coloured_cell.c17
-rw-r--r--count_total_coloured_cell.py24
2 files changed, 41 insertions, 0 deletions
diff --git a/count_total_coloured_cell.c b/count_total_coloured_cell.c
new file mode 100644
index 0000000..4e86d1b
--- /dev/null
+++ b/count_total_coloured_cell.c
@@ -0,0 +1,17 @@
+// 2579. Count Total Number of Colored Cells
+#include "leetcode.h"
+
+/*
+ * there exists an infinitely large two-dimensional grid of uncoloured unit
+ * cells. you are given a positive integer 'n', indicating that you must do the
+ * following routine for 'n' minutes: at the first minute, colour any arbitrary
+ * unit cell blue, and every minute thereafter, colour blue every uncoloured
+ * cell that touches a blue cell.
+ */
+
+long long coloredCells(int n) { return 2L * n * (n - 1) + 1; }
+
+int main() {
+ printf("%lld\n", coloredCells(1)); // expect: 1
+ printf("%lld\n", coloredCells(2)); // expect: 5
+}
diff --git a/count_total_coloured_cell.py b/count_total_coloured_cell.py
new file mode 100644
index 0000000..bcff9a9
--- /dev/null
+++ b/count_total_coloured_cell.py
@@ -0,0 +1,24 @@
+# 2579. Count Total Number of Colored Cells
+
+"""
+there exists an infinitely large two-dimensional grid of uncoloured unit
+cells. you are given a positive integer 'n', indicating that you must do the
+following routine for 'n' minutes: at the first minute, colour any arbitrary
+unit cell blue, and every minute thereafter, colour blue every uncoloured
+cell that touches a blue cell.
+"""
+
+
+class Solution(object):
+ def coloredCells(self, n):
+ """
+ :type n: int
+ :rtype: int
+ """
+ return 1 + 4 * sum(range(n))
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.coloredCells(n=1))
+ print(obj.coloredCells(n=2))