Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

(This question is a variation of the LeetCode question 723. Candy Crush. If you haven't completed that question yet, it is recommended to solve it first.)

You are given an integer matrix bubbles, where each positive integer represents a bubble color. Two cells are orthogonal neighbors when they share a side. For example, the highlighted cells below are the orthogonal neighbors of cell A.

Test Cases
Input
Output
Expected