Skip to the code
+25 XP

#423 Biggest Magic Wand Selection

medium

An image editor's magic wand selects a pixel and every pixel connected to it (up, down, left, or right) that has exactly the same color. The image is a grid of color numbers.

Write biggestSelection(image) that returns the largest number of pixels any single magic wand click could select.

Example 1

Input: image = [[1,1,2],[1,1,2],[3,3,2]]
Output: 4

The four 1s in the top-left touch each other. The 2s make 3 and the 3s make 2.

Example 2

Input: image = [[5]]
Output: 1

A single pixel is a selection of 1.

Constraints

  • 1 <= image.length, image[i].length <= 200
  • 0 <= image[i][j] <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).