Skip to content
Optimal Lab

Practice · 8 problems

Graphs

0 of 8 solved on this device

Watch it first · interactiveBFS vs DFS →Read the explainer · optimal-roundWhen to use it, and its look-alikes ↗
  1. 029Number of IslandsGiven an m x n binary grid where '1' is land and '0' is water, return the number of islands. An island is land connected 4-directionally and surrounded by water.Medium
  2. 030Course ScheduleThere are `numCourses` courses labelled 0..numCourses-1 and a list of prerequisite pairs [a, b] meaning you must take b before a. Return true if you can finish every course.Medium
  3. 031Clone GraphGiven a reference to a node in a connected undirected graph, return a deep copy of the entire graph. A node is { val, neighbors }.Medium
  4. 073Max Area of IslandGiven an m x n binary grid where 1 is land and 0 is water, return the area of the largest island (land connected 4-directionally). Return 0 if there is no island.Medium
  5. 074Rotting OrangesIn an m x n grid, 0 is empty, 1 is a fresh orange and 2 is rotten. Each minute, every fresh orange adjacent (4-directionally) to a rotten one becomes rotten. Return the minutes until no fresh orange remains, or -1 if that is impossible.Medium
  6. 075Pacific Atlantic Water FlowGiven an m x n matrix of cell heights, the Pacific touches the top and left edges and the Atlantic the bottom and right edges. Water flows from a cell to a neighbor of equal or lower height. Return all cells from which water can reach BOTH oceans.Medium
  7. 117Surrounded RegionsGiven an m x n board of 'X' and 'O', capture every region of 'O' that is completely surrounded by 'X' by flipping those cells to 'X'. A region touching the border is never captured.Medium
  8. 118Word LadderGiven `beginWord`, `endWord` and a `wordList`, a transformation sequence changes one letter at a time and every intermediate word must be in the list. Return the number of words in the shortest such sequence, or 0 if none exists.Hard