Solo practiceA little space to think.
A HACKERBREWERY ORIGINAL

Islands in the brew

MediumGraphsDepth-first search

A rectangular grid contains 1 for land and 0 for water. Count the islands. Land cells belong to the same island when they touch horizontally or vertically; touching at a corner does not connect them. Return zero for an empty grid.

Example 1

INPUT[[1,1,0],[0,0,1],[1,0,1]]OUTPUT3

The upper-left pair, lower-left cell, and right-hand pair form three islands.

Example 2

INPUT[[1,0],[0,1]]OUTPUT2

Diagonal neighbors are separate islands.

Keep in mind

  • 0 ≤ rows, columns ≤ 100
  • Every row has the same length.
  • Cells contain only 0 or 1.
Your workspace
JavaScript
Draft saved on this browserSpaces: 2 UTF-8
Try an idea. See what happens.
INPUT[[1,1,0],[0,0,1],[1,0,1]]
EXPECTED OUTPUT3

Public samples only. These checks do not award ranked points.

The vibe
Your problem set 2 selected

Local preview · up to 6 tabs in this browser

A perfect pairArrays · Hash mapsEasyKeep it togetherStrings · StacksEasyTwo queues, one counterArrays · Two pointersEasySomething differentStrings · Sliding windowMediumIslands in the brewGraphs · Depth-first searchMediumThe long way homeGraphs · Shortest pathsHard
HackerBrewery

This is an early, local preview. Create a room, open its link in another tab in this browser, and try a session together. Room chat and sample progress update between those tabs.

Links do not connect different devices yet. Networked rooms, WebRTC, accounts, and ranked judging are still being built. Sample checks are public practice checks, not ranked verdicts.

Choose the name other tabs in your local room will see.