Game Rules Players interact with a board filled with colored bubbles. When a player…
- User
Game Rules Players interact with a board filled with colored bubbles. When a player clicks on a bubble: All bubbles of the same color connected to the clicked bubble (including diagonal neighbors) are "popped" and removed from the board. Bubbles above the popped bubbles fall down to fill the empty spaces. Coding Challenge Details Input: bubbles: A 2D array representing the game board. Each cell contains an integer representing a bubble's color (0 for empty). operations: A 2D array where each inner array represents a player's move (row and column of the clicked cell). Output: A 2D array representing the final state of the game board after processing all player moves. Example bubbles = [ [1, 1, 1, 4, 3], [4, 2, 3, 4, 3], [1, 3, 2, 2, 2], [4, 5, 2, 1, 4] ] operations = [ [1, 1], [3, 3], [3, 0] ] Output: [ [0, 0, 0, 0, 0], [0, 0, 0, 4, 3], [1, 3, 2, 4, 3], [4, 5, 2, 1, 4] ]
Task: Your goal is to write a C++ function solution(bubbles, operations) that takes the game board and player moves as input and returns the final state of the board after processing all moves. Constraints: Efficiency is important. Aim for a solution with time complexity no worse than O(bubbles.length * bubbles[0].length * operations.length). There are constraints on the input size: 1 ≤ bubbles.length ≤ 30 1 ≤ bubbles[0].length ≤ 30 1 ≤ bubbles[i][j] ≤ 900
please answer the given question in c++
- Assistant