question link : codeforces.com/... Telegram channel link : t.me/joinchat/... Instagram link : www.instagram.... solution link : codeforces.com/...
Пікірлер: 105
@sangraampatwardhan15734 жыл бұрын
Hey I have a doubt, it was mentioned in the question that we can't do two or more consecutive left moves, how did you take care of that condition?
@ramanmanocha48004 жыл бұрын
Exactly I have the same doubt
@av1shekps4 жыл бұрын
Me too same doubt
@codeExplainer4 жыл бұрын
For two consecutive back condition, I think that case will not occur because it will go back only when it has encountered a large number. Like in 1,3,5,4,2 it will go back after 5 but when it goes back it will move forward because that large number can be added again.
@sangraampatwardhan15734 жыл бұрын
@@codeExplainer so the condition was redundant 😂
@crossover74603 жыл бұрын
@@codeExplainer God level thinking
@ayushagrawal2584 жыл бұрын
For two consecutive back condition, I think that case will not occur because it will go back only when it has encountered a large number. Like in 1,3,5,4,2 it will go back after 5 but when it goes back it will move forward because that large number can be added again.
@codeExplainer4 жыл бұрын
yes true , you are right , because dp do it optimally and thus it will never happen it will back in LL fashion.
@priyanshigarg92544 жыл бұрын
If the array is 1,6,5,4,2 ,, then will it go from 4 to 5 and then from 5 to 6 ?
@ayushagrawal2584 жыл бұрын
@@priyanshigarg9254 nope. It will go like 1 then 6 -> 5 -> 6 -> 5 -> 6. It will give a sum of 29 in 5 moves including 2 backwards moves.
@priyanshigarg92544 жыл бұрын
@@ayushagrawal258 Thanks for clarifying 😊
@prijwalrajavat58114 жыл бұрын
Also, you can't perform two or more moves to the left in a row. , how this code is handling this line ?
@gauravkasat44674 жыл бұрын
exactly
@vamsia55434 жыл бұрын
It does handle that case becoz first we are moving towards right, when that recursive call is exhausted then we move towards left .If we were to move that left recursive call first then it means you are moving >=2 steps towrds left which is wrong
@rbiswas8764 жыл бұрын
@@vamsia5543 suppose recursion goes as follows : LLLL LLLR LLRL LLRR so here two LL moves can occurs
@gauravkasat44674 жыл бұрын
@@vamsia5543 didn't get your logic
@prijwalrajavat58114 жыл бұрын
@@vamsia5543 got that, thanks !!
@tushargupta7644 жыл бұрын
Can you show tell me an example where we move left two times or will it never happen ? Thanks nice explanation
@codeExplainer4 жыл бұрын
Yes we can. For two consecutive back condition, I think that case will not occur because it will go back only when it has encountered a large number. Like in 1,3,5,4,2 it will go back after 5 but when it goes back it will move forward because that large number can be added again.
@ishaankaustav7272 жыл бұрын
it should be k-1 in ok function because we had already made one move while coming from 0th index to 1st index ?
@dineshbs66354 жыл бұрын
Wow, the approach is clean. I got the recursive solution and got tle same as you. But i failed to realise that it is a dp.
@codeExplainer4 жыл бұрын
hahahah , no problem , keep practicing and u will also learn new things daily.
@rushisatani31704 жыл бұрын
Thanks for the solution buddy Much appreciated 🙌
@codeExplainer4 жыл бұрын
No problem 👍 . keep coding , and I am there for your help.
@Abhishek-Jain4 жыл бұрын
Bhai memoization ka best resource kya hai?
@codeExplainer4 жыл бұрын
u can view my dp series , or code n code videos are also good. and go to gfg dp problem page , and there are a lot of prob there, solve them and learn along the way..
@MdZeeshan-gd1nw4 жыл бұрын
The dimension of dp should be [n][m][z] ie 3. bcoz the ans will depend on what moves was taken previously ie.( right/left)
@codeExplainer4 жыл бұрын
i have explained in the video , in every step k is decreased and we only have to see the variables , which defines a state , but k is decreases in every case , and thus it cannot be used . u can also understand that dp[n][m][z] , cannot occur because the size of n and m are 10^5 and thus u cannot make a array 2 values , which are that much large .
@MdZeeshan-gd1nw4 жыл бұрын
@@codeExplainer sry ,we need to make dp[n][z][2]. where 2 is used for left and right.
@VishalYadav-gk1kg5 ай бұрын
Very nice explanation sir, Thank you!
@codeExplainer5 ай бұрын
Most welcome!
@chinmaym74794 жыл бұрын
What about 2 consecutive left moves...I think there should be another Boolean state of last move
@codeExplainer4 жыл бұрын
More than 2 consecutive left move will not occur in such case. and that case will be taken care by dp approach . also as we can move total of z back , whenever i move left , i decrease the total z.
@rashmiagarwal73123 жыл бұрын
Very nice... Good luck shivam 👍🏼👏👏
@codeExplainer3 жыл бұрын
Thank you so much 😄
@IzIGaMerTube4 жыл бұрын
i >= 0. If youre i = 0, then arent you supposed to get a segmentation fault since the ok method will go to the left (i will become -1)?
@codeExplainer4 жыл бұрын
but i-1 will not be processed . it will just be returned , to do any processing in ok function u have to undergo some base base. and that base handle this cond of yours.
@girishgarg28164 жыл бұрын
I thought of a greedy approach. We will find the maximum adjacent pair sum from the first k+1 numbers (Since numbers after the k+1 th position are useless). Then we will iterate through the array to our maximum adj pair sum position and try to exhaust all our backward moves there. If k is exhausted before z, then we get our ans. Otherwise if z is exhausted first then we shall move forward until k permits. How is it? I tried implementing it but it showed WA
@avikmallick90372 жыл бұрын
I thought of exactly same, but stuck on implementation
@shivamgurjar897910 ай бұрын
Thank you very much .
@nisarggogate89524 жыл бұрын
I think you forgot the condn that there cant be more than two consiquitve moves to the left
@nisarggogate89524 жыл бұрын
Got it my bad
@tushargupta7644 жыл бұрын
@@nisarggogate8952 Can u explain a little
@shubhampokhriyal84914 жыл бұрын
Can you explain how his function is taking care of two consecutive left move??
@siddharthmagadum164 жыл бұрын
Can you explain???
@kongzilla28974 жыл бұрын
@@nisarggogate8952 can u explain?
@shethnisarg30494 жыл бұрын
please keep making such videos..helps a lot
@codeExplainer4 жыл бұрын
Thank you, I will.
@mayankverma36904 жыл бұрын
brother can u please make a video on recursion? like how the values are stored in stack ?please make a video on recursion
@codeExplainer4 жыл бұрын
ok noted , i will upload it soon , thank u for the suggestion.
@visnunathan21534 жыл бұрын
is it not necessary to check for the multiple backward traversal bro? like we cant move backward twice from a particular index will that be satisfied in your approach?
@codeExplainer4 жыл бұрын
we cannot go more than k back and as u can see in the recursive function , if i go back , my "zz" is decreased , and thus it will keep on decreasing , also this is trick thing in the question , that we should not move more than 2 back, but that case wont happen actually , in real u will only not go back more than 2 times consecutive . u can get this if u write it on paper.
@visnunathan21534 жыл бұрын
@@codeExplainer For example if I am at index 4 and still my z value is 3 then I can move to index 3 or index 5 from index 3 i will again have the possibility to move front or back as my zz value will be 2 if i choose the path of moving backwards will it not move backwards twice?
@girishgarg28164 жыл бұрын
against the question. Once we move back, our next move has to be forward
@visnunathan21534 жыл бұрын
Girish Garg will this approach satisfy what u said bro?
@girishgarg28164 жыл бұрын
@@visnunathan2153 "In a row" means "in succession", i. e. "you can't perform two or more moves to the left in a row" means that if your last action was "move to the left", you cannot move to the left right now (you can move to the left only after moving to the right).
@cyrusthapa41493 жыл бұрын
Bhai maza aagya 🔥
@codeExplainer3 жыл бұрын
welcome..
@nileshkumar96794 жыл бұрын
Thank you bro nice explanation please make video yesterday div-2 problem
@codeExplainer4 жыл бұрын
sure , i Will make on it also soon , stay tuned.
@TahsinAhmed-yj9ns4 жыл бұрын
Awesome approach!
@codeExplainer4 жыл бұрын
Glad you think so! tc . keep coding.
@ANUPKUMAR-cn7vq4 жыл бұрын
bro please explain bottom up approach as this is easy to think but bottom up is very tricky
@codeExplainer4 жыл бұрын
u can watch secondThread video for bottom up approach . u will understand more from there.
@ANUPKUMAR-cn7vq4 жыл бұрын
@@codeExplainer link ? of second thread plz
@Page_Turners_Hub4 жыл бұрын
Do you stammer ? Anyways, your videos are helpful..🙂🙂
@codeExplainer4 жыл бұрын
i m trying to be good in english speaking.
@nikhilkumar-ot9rn4 жыл бұрын
awesome bro !!!!!!!!!!!!!1 keep up the good work!!!!!!!!!!!!
@codeExplainer4 жыл бұрын
Thanks! I will try my best. keep practing
@ajinkyakharosekar85804 жыл бұрын
Good explanation..Thanks...
@codeExplainer4 жыл бұрын
You are welcome . keep coding and keep learning.
@aj-zv1zk4 жыл бұрын
Bro if i= n-1 how will u make right move?
@vamsia55434 жыл бұрын
if i is n-1 then you will add the value and make rec call to right then u notice that you've reached i==n which is the base case handled above then you return to previous state. So youre not making any further step to right
@aj-zv1zk4 жыл бұрын
@@vamsia5543 thanks
@codeExplainer4 жыл бұрын
True , Vamsi A has explained it well .
@madhavnagpal18604 жыл бұрын
you have not understood the problem , you can't move consective lefts
@codeExplainer4 жыл бұрын
i understood your point , but by the dp approach , that case wont happen , because it will take care of that case. also u can see even if u go back my zz does not become new again , it is decreased with every left move and thus if u move back my zz decrease by 1 every time and thus in total i can move a total of k back max.
@harshitagarwal90264 жыл бұрын
Thanks bro
@codeExplainer4 жыл бұрын
Welcome.
@mohamednasser32494 жыл бұрын
the solution gives me MLE on test 3
@mohamednasser32494 жыл бұрын
got accepted after making the array globally
@codeExplainer4 жыл бұрын
I always provide solution which is working.
@prabhusubramanian12054 жыл бұрын
Waiting for prob C solution bro!!
@codeExplainer4 жыл бұрын
Sure , it will be uploaded soon.
@av1shekps4 жыл бұрын
@@codeExplainer you missed to tell which condition will take care that we can not move two times left continuously.
@harshgarg70254 жыл бұрын
Bro, you are just a pupil on codeforces and you have teaching. That's doesn't make any sense. P.S. - But you are explaining concept very nicely.
@siddharthmagadum164 жыл бұрын
Might be he is learning the concepts by teaching others. Bcoz if you teach a concept to someone, you will remember it for a longer period time.
@codeExplainer4 жыл бұрын
Wow , I know but surely I will improve my rating , no worries i want the best for you . keep practicing . Ranking is just a number before the placement . I love to participate and post solutions.