Загрузка...

LeetCode 1391 Medium 🔥 | Valid Path in Grid | Graph + BFS Trick 🚀

🚀 LeetCode Problem of the Day (POTD)
Problem 1391: Check if There is a Valid Path in a Grid

In this video, we solve a medium-level problem using Graph + BFS/DFS approach 🔥

🧠 Problem:
You are given a grid where each cell represents a street type.

👉 Each type connects in specific directions:
1 → left and right
2 → up and down
3 → left and down
4 → right and down
5 → left and up
6 → right and up

🎯 Goal:
Check if there exists a valid path from top-left to bottom-right.

🎯 Approach:
- Treat grid as a graph
- Move only if both cells are connected properly
- Use BFS or DFS to traverse
- Validate direction compatibility

👉 Key Insight:
Connection must be valid from BOTH sides, not just one!

⏱️ Time Complexity: O(m * n)
💾 Space Complexity: O(m * n)

🧪 Example:
grid = [[2,4,3],
[6,5,2]]
Output: true

🔥 Why Important?
- Graph traversal in grid
- Direction mapping logic
- Interview favorite

#LeetCode #DSA #Coding #Programming #Graph #BFS #DFS #MediumProblem #InterviewPrep #codestorywithmic

Видео LeetCode 1391 Medium 🔥 | Valid Path in Grid | Graph + BFS Trick 🚀 канала codewithMIC
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять