Striver, your DSA Sheet is absolutely phenomenal! It's been an invaluable resource for mastering data structures and algorithms. Looking forward to the remaining topics, especially the much-anticipated sections on strings and heaps. Thanks for all your hard work!
Happy to share that I was able to self solve it class Solution { public boolean canJump(int[] nums) { if (nums.length == 1) return true; if (nums.length == 2) return nums[0] > 0; int last = nums.length -1, prev = nums.length -2; while (prev >=0) { if (nums[prev] > 0) { prev--; last--; } else { while(prev >= 0 && prev+nums[prev] < last) { prev--; } if (prev>=0 && prev + nums[prev] >= last) { last = prev; prev--; } else { return false; } } } return last == 0; } } As I had idea via Striver's DP problem to start from last, KUDOS striver 🔥
Understood striver. Thanks a lot Anyone interested in python code - from typing import List """ Idea is that I need to be able to cross 0 I'll keep checking greedily if the maxIndexReachable is more than current index + val at current index DRY Run 2,3 --> possible. No big deal (in first iteration only maxIndex reachable works fine) 2,1,0,4 --> not possible since max index never cross the index of 0 which is 2. When the iteration reaches index 3(4) it'll see than curIndex is strictly more than maxindex(2). So that's our flag to return false. """ class Solution: def canJump(self, nums: List[int]) -> bool: maxIndexReachable = 0 n = len(nums) target = n - 1 for i in range(n): if i > maxIndexReachable: return False maxIndexReachable = max(maxIndexReachable, i+nums[i]) return maxIndexReachable >= target
Thankyou so much Striver for all you efforts throughout in delivering us so much valuable content. Any student / working professional can now be able to transition their career without paying money for courses. Would also like your insights on the point : While preparing for interviews most of the aspirants are going through the videos solely and solving the question after completely watching the video. And also are feeling lazy trying to solve the question on our own. What is the best way to complete any topic without being lazy and how should an aspirant approach any topic/playlist?
by not watching the video first and try to solve the question beforehand. And you talk about laziness to solve a question that help you land a job bro, you shouldn't be even asking this question if you were motivated enough
This is similar to Buy and sell stock 1 here basically we need to figure out whether we can able to jump to last index or not so let's say as he mention from particular index I he can jump to at max 6 and try to traversing the array by calculating from that index what is the jump possobile at any moment lets at index I he can go to max of x but to reach till I the max possible jump we can take is y if y
Striver, your DSA Sheet is absolutely phenomenal! It's been an invaluable resource for mastering data structures and algorithms. Looking forward to the remaining topics, especially the much-anticipated sections on strings and heaps. Thanks for all your hard work!
After watching the DP Approach this greedy code is far very easy .
i thought about recursion approach but this is really easy and optimal
Radhe Radhe bhaiya 💖
waiting for String playlist ❤ and till now all the videos of greedy are osm
Good question:
class Solution {
public:
bool canJump(vector& nums) {
if(nums.size() == 1)
return true;
bool zero = false;
for(const auto &it : nums){
if(it==0){
zero = true;
break;
}
}
if(!zero)
return true;
int maxIndexReached = 0;
for(auto i = 0; i < nums.size(); i++){
if(i > maxIndexReached)
return false;
maxIndexReached = max(maxIndexReached, (i + nums[i]));
if(maxIndexReached >= nums.size()-1)
return true;
}
return true;
}
};
Amazing Explanation Sir your are awasome
Waiting for strings ...
do you come to menace and monk streams
@@KartikeyTT no
@@Josuke217 okay
Happy to share that I was able to self solve it
class Solution {
public boolean canJump(int[] nums) {
if (nums.length == 1)
return true;
if (nums.length == 2)
return nums[0] > 0;
int last = nums.length -1, prev = nums.length -2;
while (prev >=0) {
if (nums[prev] > 0) {
prev--;
last--;
} else {
while(prev >= 0 && prev+nums[prev] < last) {
prev--;
}
if (prev>=0 && prev + nums[prev] >= last) {
last = prev;
prev--;
} else {
return false;
}
}
}
return last == 0;
}
}
As I had idea via Striver's DP problem to start from last, KUDOS striver
🔥
"UNDERSTOOD BHAIYA!!"
Hello guys !!! please pay attention iterate the i or n upto size not size -1 else it will not pass the few test cases :)
Before watching Greedy Algorithm, I thought it was too tough. but after watching ohh it's the easiest one.
Hey striver,in DSA a to z course there is no video on Java collections
bool canJump(vector& nums) {
int current=0;
int available=0;
for(int i=0;iavailable){
available=current;
}
else if(available==0){
return false;
}
available--;
}
return true;
}
Understood striver. Thanks a lot
Anyone interested in python code -
from typing import List
"""
Idea is that I need to be able to cross 0
I'll keep checking greedily if the maxIndexReachable is more than current index + val at current index
DRY Run
2,3 --> possible. No big deal (in first iteration only maxIndex reachable works fine)
2,1,0,4 --> not possible since max index never cross the index of 0 which is 2.
When the iteration reaches index 3(4) it'll see than curIndex is strictly more than maxindex(2).
So that's our flag to return false.
"""
class Solution:
def canJump(self, nums: List[int]) -> bool:
maxIndexReachable = 0
n = len(nums)
target = n - 1
for i in range(n):
if i > maxIndexReachable:
return False
maxIndexReachable = max(maxIndexReachable, i+nums[i])
return maxIndexReachable >= target
Thank you
We can go from last index to 1st
If we can't go then false else true
Good morning striver !
thank you so much bro
Thank you So much
why solution using normal recursion not working?
Thank you very much
Please add the links of these new videos to the A2Z Dsa sheet
thanks for the solution
Mind Benging brooo
awesome
bool canJump(vector& nums) {
int j=nums.size()-2;
while(j>=0){
if(j+nums[j]>=j+1)
j--;
else {
int k=j-1;
while(k+nums[k]=0){
k--;
}
if(k
Thankyou so much Striver for all you efforts throughout in delivering us so much valuable content. Any student / working professional can now be able to transition their career without paying money for courses.
Would also like your insights on the point :
While preparing for interviews most of the aspirants are going through the videos solely and solving the question after completely watching the video. And also are feeling lazy trying to solve the question on our own. What is the best way to complete any topic without being lazy and how should an aspirant approach any topic/playlist?
by not watching the video first and try to solve the question beforehand. And you talk about laziness to solve a question that help you land a job bro, you shouldn't be even asking this question if you were motivated enough
Best solution
This above explained solution is not working for [3,2,1,0,4] if we are starting from starting index
what's wrong in this it will be false in answer will not be able to reach till the last
please add link to this video in your a2z sheet
UNDERSTOOD;
yes this solution is not passed on the[3,2,1,0,4] this case on leet code only 146 / 172 testcases passed
it does, but try for loop until last element
for(int i=0; i maxIndex)
return false;
maxIndex = max(maxIndex, i+nums[i]);
}
Stack and Queue ki playlist daaldo bro please, eagerly waiting. Mail bhi kia thha poochhne ke lie but you did not reply
"Someone did touch you" sounds so wrong haha
what if there are multiple zeroes in the array; than the method doesn't seem to work?
why
ty sir
please,anyone can explain intution behind it, why he is not using dp here
This is similar to Buy and sell stock 1 here basically we need to figure out whether we can able to jump to last index or not so let's say as he mention from particular index I he can jump to at max 6 and try to traversing the array by calculating from that index what is the jump possobile at any moment lets at index I he can go to max of x but to reach till I the max possible jump we can take is y if y
please make a solution on the right answer
waiting for Strings playlist
Understood
understood
can anyone explain me how is this greedy
yes, for every step the mindset to jump maximum so its greedy method
please bring the string video first .A humble request from us
prefix coding pattern
paaji tussi great ho taufa
kabul karo
😂😂
❤
waste 3500 on pw java course which is not 1% of your free resource
bruh
Bhai kya padhate ho ap never understood anything in my life what u taught
watch pogo
Understood
please bring the string video first .A humble request from us
Understood
Understood