Skip to content

1765. Map of Highest Peak #1206

Answered by mah-shamim
mah-shamim asked this question in Q&A
Jan 22, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We can use a breadth-first search (BFS) approach. Here's how we can approach it step-by-step:

Problem Breakdown:

  1. Water Cells: The cells with 1 represent water cells, and their height is always 0.
  2. Land Cells: The cells with 0 represent land cells, and their height should be assigned such that adjacent land cells have a height difference of at most 1.

Approach:

  1. BFS Initialization:

    • We start by marking all the water cells (cells with value 1) as the starting points in the BFS and assign their height to 0.
    • Then we process the neighboring land cells (cells with value 0) to assign heights.
  2. BFS Traversal:

    • From each water cell, we expand outwards, increasing the height by 1 for each adjac…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Jan 22, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jan 22, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants