bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 723. Candy Crush

723. Candy Crush

Leetcode Solutions

In-place Modification Approach

  1. Define find_and_crush() to find and mark crushable candies:
    • Iterate over each candy (r, c).
    • If board[r][c] is non-zero, check for three or more same-type candies horizontally or vertically.
    • If found, mark them by setting their values to negative.
    • After marking, iterate over the board to set all negative values to zero.
    • Return a boolean indicating if any candies were crushed.
  2. Define drop() to let candies fall into empty spaces:
    • For each column, find the lowest empty space and let non-zero candies above it fall down.
  3. Repeat find_and_crush() and drop() until the board is stable (no more candies are crushed).
  4. Return the stable board.
UML Thumbnail

Separate Steps: Find, Crush, Drop Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...