Minimum number of Jumps to reach end of an array | Love Babbar DSA Sheet Q10 | Arrays | Jump Game II
Vložit
- čas přidán 20. 08. 2024
- ✅ Useful Links
𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - / codingwithprakash
𝐖𝐡𝐚𝐭𝐬𝐀𝐩𝐩𝐂𝐡𝐚𝐧𝐧𝐞𝐥 - whatsapp.com/c...
𝐋𝐢𝐧𝐤𝐞𝐝𝐢𝐧 - / prakash-shukla
SUBSCRIBE AND HIT BELL ICON TO CHECK MORE OF MY CONTENT
czcams.com/users/Pra...
Minimum number of Jumps to reach end of an array | Love Babbar DSA Sheet Q10 | Arrays | Jump Game II
𝐌𝐔𝐒𝐈𝐂 𝐂𝐑𝐄𝐃𝐈𝐓
Track: Julius Dreisig & Zeus X Crona - Invisible [NCS Release]
Music provided by NoCopyrightSounds.
Watch: • Julius Dreisig & Zeus ...
Free Download / Stream: ncs.io/Invisibl... Complete Crash Course at prakashshukla.com
Track: Axollo - Silence (ft. Josh Bogert) [NCS Release]
Music provided by NoCopyrightSounds.
Watch: • Axollo - Silence (ft. ...
Free Download / Stream: ncs.io/ASilence
✅ Useful Links
𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - instagram.com/codingwithprakash/
𝐖𝐡𝐚𝐭𝐬𝐀𝐩𝐩𝐂𝐡𝐚𝐧𝐧𝐞𝐥 - whatsapp.com/channel/0029VaACtTa4tRrpDCQc5f44
𝐋𝐢𝐧𝐤𝐞𝐝𝐢𝐧 - www.linkedin.com/in/prakash-shukla/
Hey @Prakash, Using the logic from your another video on "Minimum number of open taps to cover the garden" seemed so natural to me, though it may not be optimized solution for this problem. But want to say thanks for that showing the more intuitive and natural solution. I was able to solve this problem by myself :)
while(count < Len-1)
{
for (int i = 0; i =Len-1)
return count;
}
For GFG :-
def minJumps(self, arr, n):
if(n==1):
return 0
if(arr[0]==0):
return -1
jumps = 0
pos = 0
des = 0
for i in range(0,n-1):
des = max(des, arr[i]+i)
if(pos==i):
pos = des
jumps +=1
if(i>=des):
return -1
return jumps
thnx bro
not working on gfg
Rehne do yrr mai hi jump maar leta hu.
🥲
🥲
best comment award should go to this guy.😂😂
😅😅
Bhai meh v jump kr raha huh kyuki tumse expain nhi hoh payega
Heee Bhagwan utha le muzhee😢😭😭
For gfg test case need two modification , when having zero in the array ,
def minJumps(self, arr, n):
#code here
j=0;d=0;p=0
if arr[0]==0:return -1
for i in range(n-1):
d=max(d,arr[i]+i)
if i>=d:
return -1
if p==i:
p=d
j=j+1
return j
where j = iump,d=destination,p=position
Thanx a lot friend 👍👍
It worked
not working,test cases passed: 1109 /1113
class Solution{
static int minJumps(int[] arr){
// your code here
int count=0,current=0,max=0;
for(int i=0;i=arr.length-1)
break;
else if(max
This is giving TLE although working very good in the local Enviroment:
int jump = 0;
for(int i = 0; i< arr.length; i=(i+arr[i])){
if(arr[i] == arr.length){
return -1;
}else{
jump++;
}
}
return jump;
Excellent approach bro. Thank you.
Why the fck do i have to habdle edge cases like n=0 , divthe question setter , did not understand this...like why is he at first giving me the question, is like generating a problem, then the solution.
Main thing lies is system fldesign in dev world, but still we are fcking here
yrr itnna kaissee sochhuuu
Solution kaafi sahi thaa waise yeh
Incase question suggests that we have to return -1 if we cant reach the end. Here is the modified soln'
int Solution::jump(vector &A) {
int n=A.size();
int jump=0;
int pos=0;
int des=0;
for(int i=0;i
This solution doesn't works on gfg try again
@@gumanrathore4351 Here is the correct solution with '0' present in array :
class Solution{
static int minJumps(int[] arr){
if(arr[0] == 0 && arr.length > 1) {
return -1;
}
int maxReachable = 0;
int currPos = 0;
int jump = 0;
int i = 0;
for(; imaxReachable)
return -1;
return jump;
}
}
@@ShubhamSingh-jj1up bro ......you saved my hours to be ruined
Thank you so much bhaiya
Can you give the code of graph solution
handle 0 with this condition in for loop: if( i == pos && arr[pos] == 0 && pos == des) return -1;
whole code will look like:
static int minJumps(int[] arr){
int des = 0;
int pos = 0;
int jump = 0;
for(int i = 0; i
you saved me 😭, ive been trying to understand this shitty problem for very long
Bro this solution doesn't work on gfg
kunki inhone 1 step me better answer milte hi update kr diya
what if 3 4 step k bad better answer mile
Sir pls give solution in comment section for case 0 I tried to modify it but it's not working
Telegram grp pe aa jao
Vaise is edge case ko homework man lo aur khud try kro varna telegram pe krte hai discuss
sir dp ki kab resume kroge playlist ?
nice bhai
Why u r adding index?.. Plz let me know very confused
Its not working for var arr = [1, 2, 0, 0, 5];
Can anyone fix this
bro you have to handle this case as a base case like: if(arr[i]==0) return Integer.MAX_VALUE because you will be stuck forever when arr[i]=0 meaning you cannot jump anywhere.