Jump Game | LeetCode 55 | Backward Greedy Approach | C++
Hack Code
0:00 / 0:00
Jump Game | LeetCode 55 | Backward Greedy Approach | C++
6 просмотров · 10 дн. назад
Hack Code
11 подписчиков
6 просмотров · 10 дн. назад
In this video, I solve LeetCode 55 – Jump Game using C++ and explain the logic step by step.
The goal is to determine whether we can reach the last index of an array, where each element represents the maximum jump length from that position.
I use a Backward Greedy Approach, scanning the array from right to left and tracking the leftmost position from which the last index can be reached.
📌 Topics Covered:
Understanding the Jump Game problem
Backward traversal of an array
Greedy algorithm explained
Tracking the leftmost reachable position
Using a Boolean vector
Time and space complexity analysis
💡 Key Idea: Start from the last index and move backward. If the current position can reach the leftmost known good position, update the target to the current position. Finally, check whether index 0 can reach the end.
🔹 Problem: Jump Game
🔹 LeetCode: #55
🔹 Difficulty: Medium
🔹 Topics: Arrays, Greedy
🔹 Approach: Backward Greedy
🔹 Language: C++
🔹 Time Complexity: O(n)
🔹 Space Complexity: O(n)
💻 Source Code (C++):
https://gist.github.com/shahil020668/...