Member-only story
Game Of Life 🪦💐| Daily LeetCode Challenge | Day 12 | Coding Interview
3 min readApr 12, 2022
This question has been marked as medium level on leetcode which in reality should be easy. The reason is that the best complexity you can achieve is O(m*n) where m is the number of rows and n is the number of columns and the simplest brute force is giving exactly that (The solution was faster than 100% of other submissions!).
Let’s start with the description.
We are given a 2D array where each cell has either a 1 or 0 value, These value represents whether life is alive in the cell or dead, 1 is alive and 0 is dead. There are 8 neighbors to each cell unless it's on the border.
There are some rules to this system/game:
- Any cell dies if the total number of live neighbors is less than 2.
- Any cell survives to the next level if the total number of neighbors is 2 or 3.
- A cell dies of overpopulation if the number of neighbors is more than 3.
- A cell comes to life if the number of alive…