Skip to main content
Intermediatecoding Verified

Given a grid where true marks water and false marks land, assign heights so water cells are 0, adjacent cells differ by at most 1, and the highest peak is as high as possible.

ReportedSource: GeeksforGeeks interview experience: Snowflake USA internship 2021

Quick answerFree

Multi-source BFS from every water cell (height 0); each land cell gets distance to nearest water. O(rows x cols).

Detailed answer· 80 words

Interview Prep

Unlock the full answer with Interview Prep

Get a 80-word model answer and a runnable reference solution, plus 61 more DSA questions.

Also in Pro (₹499 / 90 days).

Reference solution· runs in the browser sandbox

Interview Prep
Unlock with Interview Prep

+ 61 more DSA questions in Interview Prep, each with the full answer.

Discussion