Leetcode Problem 1970. Last Day Where You Can Still Cross

1970. Last Day Where You Can Still Cross

Leetcode Solutions

Binary Search + Breadth-First Search

  1. Initialize the search space with left = 1 and right = n (total number of days).
  2. While left < right, perform the following steps: a. Calculate the middle day mid as left + (right - left) / 2. b. Perform BFS to check if a path exists from the top to the bottom on day mid. c. If a path exists, set left = mid + 1, otherwise set right = mid.
  3. After the binary search loop, left - 1 will be the last day when it is possible to walk from top to bottom.
UML Thumbnail

Disjoint Set Union (on land cells)

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...