LeetCode Day 25 - Jump Game (DP or Greedy?)

  Рет қаралды 50,082

Errichto Algorithms

Errichto Algorithms

Күн бұрын

Elements of the array tell us how far to the right we can jump. Can we get to the end?
Educative giveaway - gleam.io/lMAUx/errichto-educa...
Grokking the Coding Interview Course - www.educative.io/courses/grok...
Leetcode April Challenge - leetcode.com/explore/featured...
Subscribe for more educational videos on algorithms, coding interviews and competitive programming.
- Github repository: github.com/Errichto/youtube
- Live streams on 2nd YT channel and on Twitch: / errichto2 & / errichto
- FB and Twitter: / errichto & / errichto
- Frequently Asked Questions: github.com/Errichto/youtube/w...
#Coding #Programming

Пікірлер: 85
@Errichto
@Errichto 4 жыл бұрын
Educative giveaway winners were contacted via email on May 2. You can also see a censored list of winners at the beginning of this stream kzbin.info/www/bejne/l3KnlHWur759b5Y
@nissal7033
@nissal7033 4 жыл бұрын
I appreciate that your explanation are so intuitive. Almost making logical reasoning seem instinctive
@ishaangupta4125
@ishaangupta4125 4 жыл бұрын
Solving the minimum jumps you inadvertently solved jump game 2 problem on leetcode
@jimwoodward7293
@jimwoodward7293 4 жыл бұрын
Thanks Errichto -- these videos so good!
@yunjiehong4649
@yunjiehong4649 4 жыл бұрын
Some people look down on these problem, meaning it’s too easy. But there are many ways to achieve the goals, and implementing quickly is a challenge. Love your videos which are very inspiring
@camper8650
@camper8650 4 жыл бұрын
hey you got some money dude ! congrats !
@Errichto
@Errichto 4 жыл бұрын
And you get free courses ;p
@navneetarya4398
@navneetarya4398 4 жыл бұрын
@@Errichto haha... thank you so much
@miteshkumar3183
@miteshkumar3183 4 жыл бұрын
@@Errichto POSITINO
@mohdar2061
@mohdar2061 4 жыл бұрын
@@Errichto win win
@joaquinlopezmunos4013
@joaquinlopezmunos4013 4 жыл бұрын
@@Errichto bro how long have u been coding? i meen since when? how can you be so op?
@abhaypatil2000
@abhaypatil2000 3 жыл бұрын
2:54 cutest kamil😂😂😂
@rentib9136
@rentib9136 4 жыл бұрын
At first i did it with segment tree to mark at which stone i can arrive, then I understood that the total interval must be continous. It made it much easier. int m = 0; //the last stone you can get to for(int i = 0;i < nums.size();i++){ if(m < i) return 0; m = max(m, i + nums[i]); } return 1;
@5888joseph
@5888joseph 3 жыл бұрын
Brilliant!
@waatup
@waatup 4 жыл бұрын
Love your videos, I just subscribed!
@flamendless
@flamendless 4 жыл бұрын
I like that pun in the intro
@ZzwhiskeybkszZ
@ZzwhiskeybkszZ 4 жыл бұрын
Can you be a bit slower at time and space complexity analysis please? Love this series of yours by the way! Really glad I found your channel
@front-end-forge
@front-end-forge 4 жыл бұрын
`LeetCode` is just a great place to learn a lot. And solving programming challenges within time frame is just awesome. This inspired me create my own channel which solves coding problems of sololearn community challenges every weekend. And uploading my next challenge in a while.
@johncarter3151
@johncarter3151 4 жыл бұрын
That's great.!
@unlockwithjsr
@unlockwithjsr 4 жыл бұрын
Hmm, Sololearn, I am in there as well
@rafaeldietrich8050
@rafaeldietrich8050 Жыл бұрын
Amazing video! Any advice for anyone trying to self teach math? Spec with a programming focus.
@lolista
@lolista 4 жыл бұрын
can anyone tell where can I get that timer? looks like it is the same timer that shows up when I google 'timer'... but wanted it to be floating on my screen like Errichto!
@ArjunSingh-qt5jn
@ArjunSingh-qt5jn 4 жыл бұрын
HI Errichto, I really like the work you are doing, could you please make some videos on Time and Space Complexity?
@shrad6611
@shrad6611 4 жыл бұрын
For Java Programmers, instead of using pair class, we can use two integer variable num1 and num2 and initialize these values with 0,0 and then later in while loop we can update their values as we do for pair class. Easy
@AmanRaj-ce3lw
@AmanRaj-ce3lw 4 жыл бұрын
or you can use java.awt.Point
@conorhynes8633
@conorhynes8633 4 жыл бұрын
Are there any questions that use a similar approach?
@xmingw
@xmingw 4 жыл бұрын
bool canJump(vector& a) { int n = a.size(); int target = n - 1; for (int i = n - 2; i >= 0; i--) { if (i + a[i] >= target) target = i; } return target == 0; }
@ivanleon6164
@ivanleon6164 3 жыл бұрын
when i read it i tought they asked if you can reach (exactly) at last index and that you could only jump the number in the current index(forward or backward), lol. i just make things more complicated that actually are.
@sreyanchakravarty7694
@sreyanchakravarty7694 4 жыл бұрын
This is the same question I have so many times. Dp or greedy?
@RN-jo8zt
@RN-jo8zt 4 жыл бұрын
How many hours u were spending on coding sites .when u started solving problem on earlier days?
@hellowill
@hellowill 4 жыл бұрын
"Make it slightly bigger" has to be in every video
@hitensharma259
@hitensharma259 4 жыл бұрын
Your Bear and steady gene problem on HackerRank is killing me
@qazaqempire2446
@qazaqempire2446 2 жыл бұрын
hi from Kazakstan, mr Polish guy.! damn i envy your skills! i do have bachelor computer science degree, however i never practiced algo questions. now i m over 30 and struggling with this.. damn i wish i started it 10y ago! question: how many years have u been practicing algos for?
@osmanay4301
@osmanay4301 4 жыл бұрын
BFS (with queue) solution works well for this problem.
@yinghanma1314
@yinghanma1314 4 жыл бұрын
time limit exceeded
@lucygaming9726
@lucygaming9726 4 жыл бұрын
Isn't this similar to bfs?
@poo81
@poo81 2 жыл бұрын
@Errichto can you please give us a DP solution?
@siddhantkedia9925
@siddhantkedia9925 4 жыл бұрын
Errichto making puns 🤣
@yunjiehong4649
@yunjiehong4649 4 жыл бұрын
Siddhant Kedia where are puns
@shreyansh5964
@shreyansh5964 4 жыл бұрын
@@yunjiehong4649 I am here,no worries
@whitesalmon0925
@whitesalmon0925 4 жыл бұрын
I appreciate you try so hard to think like a normal programmer instead of a pro, I really appreciate it, but can you turn back to pro mode once in a while?? thank you
@vikasvishwakarma5263
@vikasvishwakarma5263 4 жыл бұрын
errichto has some special love with pair :P
@sacchidanandverma8201
@sacchidanandverma8201 4 жыл бұрын
I solved it with dp without thinking. Thanks for greedy solution.
@shivamhanda457
@shivamhanda457 4 жыл бұрын
Can u plz tell dp approach
@yunjiehong4649
@yunjiehong4649 4 жыл бұрын
Sacchidanand Verma you’re so brutal. Brute force to solve everything 😆
@sacchidanandverma8201
@sacchidanandverma8201 4 жыл бұрын
@@shivamhanda457 When you are at index i, if any index from L=i+1 to R=i+jump[i] , can take you to end then this index will also take you to end. To avoid O(n^2) complexity I query(L,R) using segment tree which gives O(n log n) complexity.
@sacchidanandverma8201
@sacchidanandverma8201 4 жыл бұрын
@@yunjiehong4649 I always start with brute force solution. 😅
@secretmystery8305
@secretmystery8305 4 жыл бұрын
Hahahah that was nice lesson. Thanks you for this all. And my one question. When you again come on live stream on KZbin. Please reply this comment.
@Errichto
@Errichto 4 жыл бұрын
I'm streaming live in 1 hour on Twitch :D www.twitch.tv/errichto
@akshatupadhyay8002
@akshatupadhyay8002 4 жыл бұрын
I did it in O(n) starting from the second last element till the first element and marked last element as "destination". For each ' i' in that range i was calculating the distance from the destination =(destination-i) and if nums[i] >= that distance i updated my destination as i And if at last my destination ==0 then returned true else false
@twrskshm
@twrskshm 4 жыл бұрын
Exactly what I did
@guilhermecorrea3604
@guilhermecorrea3604 4 жыл бұрын
me too, I went checking if it would fill the "gaps", and if got back to the beginning, return True
@sangramjitchakraborty7845
@sangramjitchakraborty7845 4 жыл бұрын
I suppose the checking can be done in O(n) time. The minimization would be O(n^2), but that can be improved using segment trees.
@vishalmishra1937
@vishalmishra1937 4 жыл бұрын
Hey is educative courses are free for every one .I am in need of that also i dont have no money to spend
@AlexSav
@AlexSav 4 жыл бұрын
7:31 in second solution you always do n steps, even if first jump can reach end position.
@Errichto
@Errichto 4 жыл бұрын
"Premature optimization is the root of all evil" don't add a break if you don't need it
@balamukundam
@balamukundam 4 жыл бұрын
cud u plz upload a video for leet code 306
@syeda.k.2934
@syeda.k.2934 4 жыл бұрын
Increase the font just a little more @Errichto
@xritzx
@xritzx 4 жыл бұрын
@consistentthoughts826
@consistentthoughts826 4 жыл бұрын
For product array except self I took 3 days to solve How to improve coding skill
@mohitmotwani9256
@mohitmotwani9256 3 жыл бұрын
practice
@shreethejashagrithaya3211
@shreethejashagrithaya3211 4 жыл бұрын
I challenge you in competitive coding in. Hello world
@asadbinsaber7260
@asadbinsaber7260 4 жыл бұрын
What things usually contains a personal competitive programming notebook? What about yours? I am trying to make one, but struggling at starting.
@Errichto
@Errichto 4 жыл бұрын
I don't know what you're talking about. I don't have any codes. There are some hard algorithms for which I copy-paste the code, like FFT - you shouldn't worry about it as a beginner though.
@asadbinsaber7260
@asadbinsaber7260 4 жыл бұрын
@@Errichto Okay, thank you.
@mohitthorat8580
@mohitthorat8580 4 жыл бұрын
Errichto, you didn't submit the second code. The accepted was from previous solution. And I am afriad that code fails when nums[0] = 0. In which case you should immediately return false. But it's possible to return true with that solution(maybe).
@XxDruidegoxX
@XxDruidegoxX 4 жыл бұрын
With his second solution, he will return true, this is what is asked to do. i = 0, i
@mohitthorat8580
@mohitthorat8580 4 жыл бұрын
@@XxDruidegoxX Hey Alex, consider this array. [0,2,1]. The answer is false. But his code will return true.
@andersonandrade644
@andersonandrade644 4 жыл бұрын
@@mohitthorat8580 No, it won't, after the first iteration i becomes 1 and can_reach is still 0, so i
@mohitthorat8580
@mohitthorat8580 4 жыл бұрын
@@andersonandrade644 cool. Looks like missed that condition.
@BedoEbied
@BedoEbied 4 жыл бұрын
I went from the end to the beginning, isn't it better?
@waatup
@waatup 4 жыл бұрын
Going from end to beginning is Θ(n) where n is the number of elements, while going from beginning to end, with 1 additional check at each step has a worst complexity of O(n) and best complexity of O(1) because you can stop as soon as you know either the current position is unreachable or you can already reach the end. When evaluated across uniformly random non-negative integers inputs, going from beginning to end is much better. Of course the test cases' integers would be heavily skewed towards 0, but in practice going from beginning to end still wins because retrieving vector/array elements from memory/cache is more expensive than doing comparisons in registers; in other words, doing 1 additional check at each step incurs very small penalty, and iterating through the array unnecessarily is more expensive.
@winning_aadict
@winning_aadict 4 жыл бұрын
Hi Errichto. I have fulfilled all the requirements for the educative courses. Please help me avail the system design interview as I am preparing for interviews currently and this would really help my preparation. Thanks in advance.
@ickywitchy4667
@ickywitchy4667 Жыл бұрын
are u the daddy of coding??
@vishalgoyal9180
@vishalgoyal9180 4 жыл бұрын
Code is in which language
@zenzen318
@zenzen318 4 жыл бұрын
C++, obviously
@mridulkumar786
@mridulkumar786 4 жыл бұрын
Most of the comments are from India
@hacker-7214
@hacker-7214 4 жыл бұрын
7:38 wont work and you pressed run code and not submit. Edit. This comment is wrong read reply
@XxDruidegoxX
@XxDruidegoxX 4 жыл бұрын
False, it will work. The reason why it will work is because of the condition in the loop : i
@hacker-7214
@hacker-7214 4 жыл бұрын
@@XxDruidegoxX nvm u're right. I thought it would be an infinite loop for some reason
@minghuili4254
@minghuili4254 4 жыл бұрын
3:37 doesnt make sense! I do not understand what are thoes numbers coming from
@NehaYadav1
@NehaYadav1 4 жыл бұрын
That is just an example Errichto took; not related to actual values in the examples .Suppose the interval is from [5,8] and can_reach= 15, now you can upgrade your interval to [9,15]
Longest Common Subsequence - Recursive and Iterative DP (LeetCode Day 26)
19:44
LeetCode 55. Jump Game (Algorithm Explained)
10:06
Nick White
Рет қаралды 77 М.
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 26 МЛН
Fast and Furious: New Zealand 🚗
00:29
How Ridiculous
Рет қаралды 45 МЛН
Google Coding Interview With A Facebook Software Engineer
49:59
Clément Mihailescu
Рет қаралды 929 М.
LeetCode Day 20 - Binary Search Tree from Preorder Traversal
19:08
Errichto Algorithms
Рет қаралды 28 М.
Leetcode Biweekly #56 (2nd Place)
15:58
Errichto Algorithms
Рет қаралды 82 М.
String in Binary Tree - LeetCode Day 30 | THE END
10:10
Errichto Algorithms
Рет қаралды 20 М.
LeetCode Odd Even Jump Solution Explained - Java
27:18
Nick White
Рет қаралды 22 М.
Google Coding Interview Question - Longest String Chain
29:58
Errichto Algorithms
Рет қаралды 75 М.
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 386 М.
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 101 М.