Skip to content

Graphs

Number of Islands

First Attempt

  • Brute force approach is to just check all 4 sides of each node
    • Iterate through grid, checking if left, right, above and below are water (or an edge in this case)
    • I am very dumb
    • Didn’t read the question properly
    • An island can be multiple lands connected together, as long as they’re surrounded by water
    • So I typed a whole bunch of completely useless code
    • Read the damn question properly