Jump Game 3 (LeetCode 1306) | Simplified solution with diagrams | Level Order Traversal | BFS
Vložit
- čas přidán 28. 07. 2024
- Actual problem on LeetCode: leetcode.com/problems/jump-ga...
Chapters:
00:00 - Intro
00:48 - Problem Statement
04:50 - How to attack the problem
09:50 - Conversion to level order traversal
13:28 - Dry-run of Code
19:33 - Final Thoughts
📚 Links to topics I talk about in the video:
Level Order Traversal: • Level order traversal ...
Binary Trees: • Binary Trees Introduct...
Jump Game 1: • Jump Game (LeetCode 55...
Jump Game 2: • Jump Game 2 (LeetCode ...
Other problems on Trees: • Trees
📘 A text based explanation is available at: studyalgorithms.com
Code on Github: github.com/nikoo28/java-solut...
Test-cases on Github: github.com/nikoo28/java-solut...
📖 Reference Books:
Starting Learn to Code: amzn.to/3sJm8Wl
Favorite book to understand algorithms: amzn.to/4848xJH
Favorite book for data structures: amzn.to/3P96YBv
Get started for interview preparation: amzn.to/44Nn5du
🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
🎥 My Recording Gear:
Recording Light: amzn.to/3PdsViT
Microphone: amzn.to/3Exv83x
Recording Camera: amzn.to/3PwyN8e
Tablet to sketch and draw: amzn.to/3ZdKVy7
Sketching Tool: amzn.to/45XJEgY
Laptop to edit videos: amzn.to/460ofDu
💻 Get Social 💻
Follow on Facebook at: / studyalgos
Subscribe to RSS feeds: studyalgorithms.com/feed/
Join fan mail: eepurl.com/g9Dadv
#leetcode #programming #interview
please keep uploading more videos, you are the best explainer I have found on youtube! kudos man
Best content on youtube ❤
The best I've ever seen
Great sir
Absolutely excellent explanation, thank you so much
Instead of taking one random problem if u take one by one concept postting problems on that topic it would be nice so that we can say ourselves we know DSA ...
there are a lof of playlists, that I am creating on the way. I am still adding a lot videos, and slowly will structure them nicely too...such that they can become a complete course.
Easy JS solution:
/**
* @param {number[]} arr
* @param {number} start
* @return {boolean}
*/
var canReach = function(arr, start) {
let queue = [];
let visited = new Set();
queue.push(start);
visited.add(start);
while (queue.length > 0) {
let position = queue.shift();
// Check if we have reached a position with value 0
if (arr[position] === 0) return true;
// Calculate new positions to move to
let newLeftPosition = position - arr[position];
let newRightPosition = position + arr[position];
// Check and add new left position if it's within bounds and not visited
if (newLeftPosition >= 0 && !visited.has(newLeftPosition)) {
queue.push(newLeftPosition);
visited.add(newLeftPosition);
}
// Check and add new right position if it's within bounds and not visited
if (newRightPosition < arr.length && !visited.has(newRightPosition)) {
queue.push(newRightPosition);
visited.add(newRightPosition);
}
}
return false;
};