Let’s define the diagonal neighbors of a given cell as the surrounding cells, with…
- User
Let’s define the diagonal neighbors of a given cell as the surrounding cells, with precisely one corner touching a corner of the given cell. The picture below shows the diagonal neighbors for the A cell.
Bubble-Popping Game Instructions:
Given a board of cells containing a bubble of a specific color, your task is to emulate a bubble-popping game. In this game, the player can click a cell every turn to pop bubbles. After clicking the cell, the following happens:
The bubble in the clicked cell and bubbles of the same color among its diagonal neighbors are "popped" and removed, resulting in empty cells. After bubbles are removed, the remaining bubbles in cells above the empty cells drop down to fill all empty cells. Nothing happens if the clicked cell is empty (it does not contain a bubble).The input consists of two arrays:
An initial board of cells bubbles - a multidimensional array of integers representing cells containing different colored bubbles. A set of player turns operations - 2-element integer arrays describing the coordinates (the row and column) of the cell that the player clicked on during each turn.Return the state of the game board after all operations are processed. The output should be a multidimensional array of integers with the same size as bubbles, but replace the integers in all empty cells (without bubbles) with 0.
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(bubbles[0].length^2 - operations.length) will fit within the execution time limit.
Example For
bubbles = [[1, 1, 1, 4, 3], [4, 1, 2, 3, 3], [1, 5, 1, 1, 2], [4, 3, 2, 2, 4]] andoperations = [[1, 1], [3, 3], [2, 2], [3, 0]]the output should be
solution(bubbles, operations) = [[0, 0, 0, 0, 0], [0, 1, 0, 4, 3], [0, 5, 0, 3, 3], [4, 3, 2, 1, 4]]give code for this problem in cpp and give optimized code
- Assistant