Doppel is a startup for detecting and taking down social engineering attacks for brands. They crossed Series B funding
Problem Description
A board is made up of an M x N grid of cells, where each cell has an initial state:
- live (represented by a letter “O”), or
- dead (represented by a dot “.”).
Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules:
- Any live cell with fewer than two live neighbors dies as if caused by under-population.
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies, as if by overpopulation.
- Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
The next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously.Implement the above logic and print the state of the board after each generation. You need to be able to run the simulation for K generations
Sample test case is provided from the interviewer which helps
Interviewer provides some sample starting boards of their choice and has you run the state of the board. Any pattern you notice? Why do you think that pattern makes sense? Just use your brain to answer this question. Shouldn't require too much thought
Look at the code you wrote. We assumed the board was finite. What if we wanted to run this code but for infinite board. What would you do to simulate an infinite grid with finite memory?
Based on what you answered in part 2, how would you optimize the implementation