Array Walk || Educational Codeforces Round 92 || CODEFORCES || DYNAMIC PROGRAMMING

  Рет қаралды 6,327

code Explainer

code Explainer

Күн бұрын

question link : codeforces.com/...
Telegram channel link : t.me/joinchat/...
Instagram link : www.instagram....
solution link : codeforces.com/...

Пікірлер: 105
@sangraampatwardhan1573
@sangraampatwardhan1573 4 жыл бұрын
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?
@ramanmanocha4800
@ramanmanocha4800 4 жыл бұрын
Exactly I have the same doubt
@av1shekps
@av1shekps 4 жыл бұрын
Me too same doubt
@codeExplainer
@codeExplainer 4 жыл бұрын
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.
@sangraampatwardhan1573
@sangraampatwardhan1573 4 жыл бұрын
@@codeExplainer so the condition was redundant 😂
@crossover7460
@crossover7460 3 жыл бұрын
@@codeExplainer God level thinking
@ayushagrawal258
@ayushagrawal258 4 жыл бұрын
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.
@codeExplainer
@codeExplainer 4 жыл бұрын
yes true , you are right , because dp do it optimally and thus it will never happen it will back in LL fashion.
@priyanshigarg9254
@priyanshigarg9254 4 жыл бұрын
If the array is 1,6,5,4,2 ,, then will it go from 4 to 5 and then from 5 to 6 ?
@ayushagrawal258
@ayushagrawal258 4 жыл бұрын
@@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.
@priyanshigarg9254
@priyanshigarg9254 4 жыл бұрын
@@ayushagrawal258 Thanks for clarifying 😊
@prijwalrajavat5811
@prijwalrajavat5811 4 жыл бұрын
Also, you can't perform two or more moves to the left in a row. , how this code is handling this line ?
@gauravkasat4467
@gauravkasat4467 4 жыл бұрын
exactly
@vamsia5543
@vamsia5543 4 жыл бұрын
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
@rbiswas876
@rbiswas876 4 жыл бұрын
@@vamsia5543 suppose recursion goes as follows : LLLL LLLR LLRL LLRR so here two LL moves can occurs
@gauravkasat4467
@gauravkasat4467 4 жыл бұрын
@@vamsia5543 didn't get your logic
@prijwalrajavat5811
@prijwalrajavat5811 4 жыл бұрын
@@vamsia5543 got that, thanks !!
@tushargupta764
@tushargupta764 4 жыл бұрын
Can you show tell me an example where we move left two times or will it never happen ? Thanks nice explanation
@codeExplainer
@codeExplainer 4 жыл бұрын
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.
@ishaankaustav727
@ishaankaustav727 2 жыл бұрын
it should be k-1 in ok function because we had already made one move while coming from 0th index to 1st index ?
@dineshbs6635
@dineshbs6635 4 жыл бұрын
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.
@codeExplainer
@codeExplainer 4 жыл бұрын
hahahah , no problem , keep practicing and u will also learn new things daily.
@rushisatani3170
@rushisatani3170 4 жыл бұрын
Thanks for the solution buddy Much appreciated 🙌
@codeExplainer
@codeExplainer 4 жыл бұрын
No problem 👍 . keep coding , and I am there for your help.
@Abhishek-Jain
@Abhishek-Jain 4 жыл бұрын
Bhai memoization ka best resource kya hai?
@codeExplainer
@codeExplainer 4 жыл бұрын
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-gd1nw
@MdZeeshan-gd1nw 4 жыл бұрын
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)
@codeExplainer
@codeExplainer 4 жыл бұрын
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-gd1nw
@MdZeeshan-gd1nw 4 жыл бұрын
@@codeExplainer sry ,we need to make dp[n][z][2]. where 2 is used for left and right.
@VishalYadav-gk1kg
@VishalYadav-gk1kg 5 ай бұрын
Very nice explanation sir, Thank you!
@codeExplainer
@codeExplainer 5 ай бұрын
Most welcome!
@chinmaym7479
@chinmaym7479 4 жыл бұрын
What about 2 consecutive left moves...I think there should be another Boolean state of last move
@codeExplainer
@codeExplainer 4 жыл бұрын
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.
@rashmiagarwal7312
@rashmiagarwal7312 3 жыл бұрын
Very nice... Good luck shivam 👍🏼👏👏
@codeExplainer
@codeExplainer 3 жыл бұрын
Thank you so much 😄
@IzIGaMerTube
@IzIGaMerTube 4 жыл бұрын
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)?
@codeExplainer
@codeExplainer 4 жыл бұрын
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.
@girishgarg2816
@girishgarg2816 4 жыл бұрын
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
@avikmallick9037
@avikmallick9037 2 жыл бұрын
I thought of exactly same, but stuck on implementation
@shivamgurjar8979
@shivamgurjar8979 10 ай бұрын
Thank you very much .
@nisarggogate8952
@nisarggogate8952 4 жыл бұрын
I think you forgot the condn that there cant be more than two consiquitve moves to the left
@nisarggogate8952
@nisarggogate8952 4 жыл бұрын
Got it my bad
@tushargupta764
@tushargupta764 4 жыл бұрын
@@nisarggogate8952 Can u explain a little
@shubhampokhriyal8491
@shubhampokhriyal8491 4 жыл бұрын
Can you explain how his function is taking care of two consecutive left move??
@siddharthmagadum16
@siddharthmagadum16 4 жыл бұрын
Can you explain???
@kongzilla2897
@kongzilla2897 4 жыл бұрын
@@nisarggogate8952 can u explain?
@shethnisarg3049
@shethnisarg3049 4 жыл бұрын
please keep making such videos..helps a lot
@codeExplainer
@codeExplainer 4 жыл бұрын
Thank you, I will.
@mayankverma3690
@mayankverma3690 4 жыл бұрын
brother can u please make a video on recursion? like how the values are stored in stack ?please make a video on recursion
@codeExplainer
@codeExplainer 4 жыл бұрын
ok noted , i will upload it soon , thank u for the suggestion.
@visnunathan2153
@visnunathan2153 4 жыл бұрын
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?
@codeExplainer
@codeExplainer 4 жыл бұрын
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.
@visnunathan2153
@visnunathan2153 4 жыл бұрын
@@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?
@girishgarg2816
@girishgarg2816 4 жыл бұрын
against the question. Once we move back, our next move has to be forward
@visnunathan2153
@visnunathan2153 4 жыл бұрын
Girish Garg will this approach satisfy what u said bro?
@girishgarg2816
@girishgarg2816 4 жыл бұрын
@@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).
@cyrusthapa4149
@cyrusthapa4149 3 жыл бұрын
Bhai maza aagya 🔥
@codeExplainer
@codeExplainer 3 жыл бұрын
welcome..
@nileshkumar9679
@nileshkumar9679 4 жыл бұрын
Thank you bro nice explanation please make video yesterday div-2 problem
@codeExplainer
@codeExplainer 4 жыл бұрын
sure , i Will make on it also soon , stay tuned.
@TahsinAhmed-yj9ns
@TahsinAhmed-yj9ns 4 жыл бұрын
Awesome approach!
@codeExplainer
@codeExplainer 4 жыл бұрын
Glad you think so! tc . keep coding.
@ANUPKUMAR-cn7vq
@ANUPKUMAR-cn7vq 4 жыл бұрын
bro please explain bottom up approach as this is easy to think but bottom up is very tricky
@codeExplainer
@codeExplainer 4 жыл бұрын
u can watch secondThread video for bottom up approach . u will understand more from there.
@ANUPKUMAR-cn7vq
@ANUPKUMAR-cn7vq 4 жыл бұрын
@@codeExplainer link ? of second thread plz
@Page_Turners_Hub
@Page_Turners_Hub 4 жыл бұрын
Do you stammer ? Anyways, your videos are helpful..🙂🙂
@codeExplainer
@codeExplainer 4 жыл бұрын
i m trying to be good in english speaking.
@nikhilkumar-ot9rn
@nikhilkumar-ot9rn 4 жыл бұрын
awesome bro !!!!!!!!!!!!!1 keep up the good work!!!!!!!!!!!!
@codeExplainer
@codeExplainer 4 жыл бұрын
Thanks! I will try my best. keep practing
@ajinkyakharosekar8580
@ajinkyakharosekar8580 4 жыл бұрын
Good explanation..Thanks...
@codeExplainer
@codeExplainer 4 жыл бұрын
You are welcome . keep coding and keep learning.
@aj-zv1zk
@aj-zv1zk 4 жыл бұрын
Bro if i= n-1 how will u make right move?
@vamsia5543
@vamsia5543 4 жыл бұрын
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-zv1zk
@aj-zv1zk 4 жыл бұрын
@@vamsia5543 thanks
@codeExplainer
@codeExplainer 4 жыл бұрын
True , Vamsi A has explained it well .
@madhavnagpal1860
@madhavnagpal1860 4 жыл бұрын
you have not understood the problem , you can't move consective lefts
@codeExplainer
@codeExplainer 4 жыл бұрын
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.
@harshitagarwal9026
@harshitagarwal9026 4 жыл бұрын
Thanks bro
@codeExplainer
@codeExplainer 4 жыл бұрын
Welcome.
@mohamednasser3249
@mohamednasser3249 4 жыл бұрын
the solution gives me MLE on test 3
@mohamednasser3249
@mohamednasser3249 4 жыл бұрын
got accepted after making the array globally
@codeExplainer
@codeExplainer 4 жыл бұрын
I always provide solution which is working.
@prabhusubramanian1205
@prabhusubramanian1205 4 жыл бұрын
Waiting for prob C solution bro!!
@codeExplainer
@codeExplainer 4 жыл бұрын
Sure , it will be uploaded soon.
@av1shekps
@av1shekps 4 жыл бұрын
@@codeExplainer you missed to tell which condition will take care that we can not move two times left continuously.
@harshgarg7025
@harshgarg7025 4 жыл бұрын
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.
@siddharthmagadum16
@siddharthmagadum16 4 жыл бұрын
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.
@codeExplainer
@codeExplainer 4 жыл бұрын
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.
A. Remove Smallest || Codeforces Round #661 (Div. 3) || CODEFORCES
2:45
Good Subarrays ||  Educational Codeforces Round 93 || CODEFORCES
11:27
code Explainer
Рет қаралды 10 М.
The Joker wanted to stand at the front, but unexpectedly was beaten up by Officer Rabbit
00:12
Остановили аттракцион из-за дочки!
00:42
Victoria Portfolio
Рет қаралды 3,5 МЛН
Every parent is like this ❤️💚💚💜💙
00:10
Like Asiya
Рет қаралды 7 МЛН
touristream 012: Codeforces Round 672 (Div. 2)
2:02:08
Gennady Korotkevich
Рет қаралды 238 М.
LCM Problem || Educational Codeforces Round 92 || CODEFORCES
4:16
code Explainer
Рет қаралды 5 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 76 М.
Codeforces Educational Round 92 A-F Solutions + Screencast  (Reupload)
2:38:33
Winning Codeforces Round 971 (Div. 4) in honor of @que_tourist
1:39:42
Codeforces Round 641 | Orac and LCM | Maths
7:10
take U forward
Рет қаралды 9 М.
(Problem-C) Good String | Codeforces Educational Round 92
11:14
Hitesh Tripathi
Рет қаралды 6 М.