According to theĀ Wikipedia’s article: “TheĀ Game of Life, also known simply asĀ Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”
Given aĀ boardĀ withĀ mĀ byĀ nĀ cells, each cell has an initial stateĀ liveĀ (1) orĀ deadĀ (0). Each cell interacts with itsĀ eight neighborsĀ (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):
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 over-population..
Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
Write a function to compute the next state (after one update) of the board given its current state.Ā The next state is created by applying the above rules simultaneously to every cell in the current state, whereĀ births and deaths occur simultaneously.
Could you solve it in-place? Remember that the board needs to be updated at the same time: You cannot update some cells first and then use their updated values to update other cells.
In this question, we represent the board using a 2D array. In principle, the board is infinite, which would cause problems when the active area encroaches the border of the array. How would you address these problems?
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coordinates don’t matter and hence the x-coordinates of start and end of the diameter suffice. Start is always smaller than end. There will be at most 104Ā balloons.
An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with xstartĀ and xendbursts by an arrow shot at x if xstartĀ ā¤ x ā¤ xend. There is no limit to the number of arrows that can be shot. An arrow once shot keeps travelling up infinitely. The problem is to find the minimum number of arrows that must be shot to burst all balloons.
Example:
Input:
[[10,16], [2,8], [1,6], [7,12]]
Output:
2
Explanation:
One way is to shoot one arrow for example at x = 6 (bursting the balloons [2,8] and [1,6]) and another arrow at x = 11 (bursting the other two balloons).