Problem 30: Find Distance to nearest Exit[Google]
Shortest Distance, Graph Traversal, Path Finding
What’s shaking my awesome readers,
Today’s question is a favorite of Google. It tests your knowledge, problem-solving ability, and ability to recognize the right approach. Let’s get into it.
Problem
This problem was asked by Google.
You are given a m x n 2D grid initialized with these three possible values:
-1 - A wall or an obstacle.
0 - A gate.
INF - Infinity means an empty room.
Fill each empty room with the distance to its nearest gate. If it is impossible to reach a gate, it should be filled with INF.
For example, given the 2D grid:
INF -1 0 INF
INF INF INF -1
INF -1 INF -1
0 -1 INF INF
After running your function, the 2D grid should be:
3 -1 0 1
2 2 1 -1
1 -1 2 -1
0 -1 3 4
Make sure you like this question on Substack. It really helps the newsletter grow. The solution to this problem will be shared tomorrow with the premium subscribers of the newsletter.
For a free trial of the newsletter, subscribe here. This will give you month-long access to the newsletter. This offer runs out May 13,2022; so act quickly!!!
Consider filling out this survey. This helps me understand you better and will allow me to improve the content: Link: https://forms.gle/XfTXSjnC8W2wR9qT9
Struggling to Prepare for Coding Interviews? Stuck on Leetcode Questions? Too busy to go through the endless resources available online? Subscribe to Coding Interviews Made Simple, a newsletter to help you succeed with your newsletter. Using techniques developed through my proven track record of mentoring people with their interviews, I will help you ace your FAANG/MAMAA (and other Software Engineering) interviews. Get 20% for a full year using this special offer.
Happy Prep. I’ll see you at your dream job.
The funniest coding newsletter writer,
Devansh <3
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75