Optimal Strategy for a Game Dynamic Programming

Поділитися
Вставка
  • Опубліковано 26 сер 2024
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the problem optimal strategy for a game using dynamic programming. In this problem,
    1. You are given an array(arr) of length N, where N is an even number.
    2. The elements of the array represent N coins of values arr1,arr1...arrN.
    3. You are playing a game against an opponent in an alternative way, where the opponent is equally smart.
    4. In this game, a player selects either the first or the last coin from the row in every turn, removes it from the row permanently, and receives the value of the coin.
    5. You have to find the maximum possible amount of money you can win if you make the first move.
    To attempt and to submit this problem, click here: www.pepcoding....
    For a better experience and more exercises, VISIT: www.pepcoding....
    #dynamicprogramming #algorithms #datastructure
    Have a look at our result: www.pepcoding....
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education

КОМЕНТАРІ • 218

  • @garvitrajput8491
    @garvitrajput8491 2 роки тому +57

    That one line"When you do things DO YOUR BEST and when things happen to you assume the worst case" sums up the whole question. Thank you for this !

    • @rohhittz
      @rohhittz 4 місяці тому +1

      Plot twist... they are not talking about the question, they are talking about life 😊

    • @pratikchakraborty8058
      @pratikchakraborty8058 3 місяці тому

      @@rohhittz Hence, algorithms are applicable in real life too!

    • @rohhittz
      @rohhittz 3 місяці тому

      @@pratikchakraborty8058 yess..✅

  • @tusharjajodia9077
    @tusharjajodia9077 3 роки тому +47

    This is a crime against other UA-cam Channel.
    Simply the best.

    • @Pepcoding
      @Pepcoding  3 роки тому +15

      Haha Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

  • @meme_engineering4521
    @meme_engineering4521 3 роки тому +77

    This video teaches a life lesson: "When you do something, do your best. But when things happen to you, prepare for the worst", BTW amazing content sir

    • @noobevsprorelation6838
      @noobevsprorelation6838 3 роки тому +2

      hope for the best prepare for the worse ......

    • @capone2676
      @capone2676 2 роки тому +1

      i was just about to comment that, and then i saw your comment on top. Lol. Murphy's law apparently.

  • @sakshamsolanki235
    @sakshamsolanki235 3 роки тому +38

    This man teaches things on next level, keep making the superb content sir..

    • @Pepcoding
      @Pepcoding  3 роки тому +8

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

    • @sakshamsolanki235
      @sakshamsolanki235 3 роки тому +1

      @@Pepcoding Done sir😊😊

  • @samirhembrom2559
    @samirhembrom2559 4 місяці тому

    POTD tha ajka Meine min aur max ka condition k bare mein nhi socha tha sirf max lekar forward ja raha tha. Great video samjh agya pura

  • @sujoyseal195
    @sujoyseal195 3 роки тому +5

    You teach so well that at 7:50 , I got concept of the entire video and didn't had to watch the entire video. You are great

    • @enigma2886
      @enigma2886 3 роки тому +1

      same bruh

    • @maheshvoleti6990
      @maheshvoleti6990 2 роки тому

      Yes,opponent also trying to win[so he also will take the maximum value] .this is the main logic to understand for whole question

  • @23cash86
    @23cash86 2 місяці тому

    I saw this video few weeks back to understand a solution, i came back here to mention how useful this video was in applying logic to other similar questions....great video sir!

  • @akshaysolanki5164
    @akshaysolanki5164 3 роки тому +1

    ek number sir, seriously. Main kisi bhi sawal me stuck ho jata hu toh sbse pehle youtube pr aapki videos search krta hu. Next level explanations hoti hai aapki.

  • @aniketverma7786
    @aniketverma7786 3 роки тому +9

    Scratched my head for almost 2 3 hours for knowing why we are doing in min operation rather than max operation
    And when I saw the video, I got the reason in just 2 to 3 min, you have explained this thing in such a fantastic way
    Thanks, you style of teaching is phenomenal
    🙏🙏🙏🙏🙏🙏

    • @Pepcoding
      @Pepcoding  3 роки тому +8

      Thank you so much beta aur agr questions banne lge to ghamand nh krna aur agr naa ho to haar nh maan ni.
      Aur aise h apna pyaar bnaye rkhe aur pdte rhe😊

    • @mohitsinha1994
      @mohitsinha1994 3 роки тому +1

      what is wrong in selecting max? i am still not able to get?

  • @divyamgupta6415
    @divyamgupta6415 3 роки тому +1

    Sir ek to aapki teaching itni lajawaab and usko jb dark mode pe implement krre to maza hi aajata h.
    You are best.

    • @Pepcoding
      @Pepcoding  3 роки тому

      Haha...thankyou beta!
      Keep watching and keep learning

  • @harshwardhanchaube706
    @harshwardhanchaube706 2 роки тому +1

    u explained the entire question in one philosophical line....................wow

  • @abhayroadlines528
    @abhayroadlines528 3 дні тому

    Excellent explanation sir... I was so confused in this question before this explanation.

  • @rajkishorpradhan8543
    @rajkishorpradhan8543 3 роки тому +4

    One of the best explanations on Optimal game strategy, feels very much enlingtned after watching this

    • @Pepcoding
      @Pepcoding  3 роки тому

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

  • @yuvrajsinghcme1143
    @yuvrajsinghcme1143 2 роки тому +1

    if i will join the pepcoding in the future ,reason will be sumeet sir,he is amazing teacher i have ever met.

  • @akshaykapadia8359
    @akshaykapadia8359 3 місяці тому

    The way you explain is just outstanding. Couldnt understand this by reading leetcode solutions

  • @raja_krishnappa_bariya
    @raja_krishnappa_bariya 7 місяців тому

    In telugu theres a phrase which is apt "em chappad ra" (sunil meme). world class teaching.

  • @Angel-486
    @Angel-486 2 роки тому +2

    I've just started to understand how works dynamic programmation thanks to you

    • @Pepcoding
      @Pepcoding  2 роки тому

      Hope you like the video, we are going to upload 3 lakh+ videos on our platform nados.pepcoding.com
      You will find better experience and precisely arranged content.
      And for more updates keep following us on Instagram instagram.com/pepcoding/

  • @alpishjain1317
    @alpishjain1317 3 роки тому +1

    This question came in the online coding round of Loginext solutions!Thanks for the video.

  • @Senshiii99
    @Senshiii99 3 роки тому +7

    The smoothest explanation in UA-cam history

  • @shraddhadey9724
    @shraddhadey9724 3 роки тому

    Hello, sir, I have 11 years of experience working but this type of concept explanation is really brilliant. Thanks for posting such videos.

    • @techsavy5669
      @techsavy5669 2 роки тому +1

      ..same company from the beginning !?

  • @harshitavyas7497
    @harshitavyas7497 2 роки тому

    Sir you are god of programming!!
    Simply best and you concentrate on building the fundamentals instead of just reading out the code....
    Thanku so much sir!

  • @raviashwin1157
    @raviashwin1157 3 роки тому +10

    GOD LEVEL EXPLANATION❤️

    • @Pepcoding
      @Pepcoding  3 роки тому

      👐 keep motivating, keep learning and keep loving Pepcoding😊

  • @HARSHPIPAL
    @HARSHPIPAL 3 роки тому +1

    When pepcoding happens to you it's the best 👍

  • @SatyaPrakash-dj8ix
    @SatyaPrakash-dj8ix 3 місяці тому

    u teaching is just awesome. I m able to understand everything

  • @rajurauniyar6132
    @rajurauniyar6132 2 роки тому

    A huge thanks for doing this. I would like you to explain why DP applies in this problem when we are building the tree. You are the only channel that I have seen put your back into it to make sure that its readers learn something. Keep up the good work, Sir.

  • @devanshsharma2106
    @devanshsharma2106 2 роки тому

    sir your videos have been helping me since 1 month. THNX so much

  • @factswithai2
    @factswithai2 3 роки тому +1

    kaafi fun to learn tha ye question. Thank u sir for teaching it this good. East or west sumeet sir is the best

    • @Pepcoding
      @Pepcoding  3 роки тому

      Keep learning, Keep growing and keep loving Pepcoding!😊

  • @pc2780
    @pc2780 2 роки тому

    this is the best explanation available in internet for this problem. Thank you

    • @Pepcoding
      @Pepcoding  2 роки тому

      Glad it was helpful!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @cautioni
    @cautioni 3 роки тому +1

    I really liked the explanation, there cannot be a better explanation than this but code mei aate hi gap strategy thoda explain krte toh easy hota smjhna, also I feel many a times you were just repeating things too many times which could be avoided and make the video shorter.

  • @adityaojha2701
    @adityaojha2701 3 роки тому +2

    The best explanation. I always love to watch your explanations.

    • @Pepcoding
      @Pepcoding  3 роки тому

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      ua-cam.com/users/Pepcodingabout?view_as=subscriber

  • @degavathanandnayak9692
    @degavathanandnayak9692 3 роки тому

    Such a great teacher you are. I am feeling regret that I found this channel so late😢

  • @dhruvjain6352
    @dhruvjain6352 3 роки тому +1

    Thank you for such a good explanation Sir .Just keep uploading videos and give us tricks to approach DP and greedy problems.
    You are a great teacher

  • @arnabmukherjee4672
    @arnabmukherjee4672 3 роки тому +2

    In search of gold we found Diamond...Sir U beauty ❤️

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

    • @arnabmukherjee4672
      @arnabmukherjee4672 3 роки тому

      @@Pepcoding ❤️

  • @tanayakarmakar2407
    @tanayakarmakar2407 3 роки тому +2

    Finally I understood this question, thanks for wonderful explanation :)

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Glad to know that you liked the content. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a review about us here - g.page/Pepcoding/review?rc

  • @pranavpratapsingh6002
    @pranavpratapsingh6002 2 роки тому

    kitta awesome padhate hai yrrrrrrrrr😘

  • @kabboghosh1853
    @kabboghosh1853 3 роки тому

    I try lot of videos ,this channel saved my life

  • @yourbestie4138
    @yourbestie4138 3 роки тому +1

    bahut badiya explanation

    • @Pepcoding
      @Pepcoding  3 роки тому

      keep motivating, keep learning and keep loving Pepcoding😊

  • @vishalrajak2417
    @vishalrajak2417 3 роки тому +2

    also sir can you add link of the video in which gap concept you had taught

  • @rohitshinde8478
    @rohitshinde8478 3 роки тому

    Sir you are made for teaching . Thank you very much for your efforts

  • @rounakagrawal4760
    @rounakagrawal4760 2 роки тому +1

    Loved it. Learnt a lot from this video❤

  • @vishalrajak2417
    @vishalrajak2417 3 роки тому

    great sir ji.. i always see gap code in dp but i have no idea how it is working.. Thanks to you for such a good illustration

    • @mickyman753
      @mickyman753 3 роки тому

      try seeing palindromic substring and plaindromic susseq question by sir to understand what is gap strategy

  • @Aditya_Shahi
    @Aditya_Shahi 2 роки тому

    Your Explanations are just amazing

  • @__k.abhishek
    @__k.abhishek 3 роки тому

    isse acha explanation ho hi nhi skta :)

  • @FinanceMode14
    @FinanceMode14 2 роки тому +1

    in which video you have explain gap strategy ?

  • @mickyman753
    @mickyman753 3 роки тому +1

    the tabulation way is way easier for me instead of recsurion here ,i tried 30 minutes still couldn't come up will recussrion call according to formula , but knowing the gap strategy the dp table is super easy to fill from the formula

  • @DeepSingh-zs2oi
    @DeepSingh-zs2oi Рік тому

    extremely nice explanation.

  • @sangamchoudhary6977
    @sangamchoudhary6977 2 роки тому +1

    brilliantly explained

  • @noobevsprorelation6838
    @noobevsprorelation6838 3 роки тому +1

    Again a masterpiece Explanation Thank You, Sir

    • @Pepcoding
      @Pepcoding  3 роки тому

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      ua-cam.com/users/Pepcodingabout?view_as=subscriber

  • @komalsai9461
    @komalsai9461 6 місяців тому

    Great explaination

  • @amoghupadhayay2502
    @amoghupadhayay2502 2 роки тому

    Man...Hats OFF!! Thank You!

  • @supriyasharma6934
    @supriyasharma6934 2 роки тому +2

    Excellent video.
    Could you please tell me in which kind of scenarios is it necessary to use the gap strategy?

  • @swetajha2265
    @swetajha2265 2 роки тому

    Excellent explanation. Thank you!!

  • @abhishek__anand__
    @abhishek__anand__ Рік тому

    Great Explanation

  • @soumyadeepdas1536
    @soumyadeepdas1536 Рік тому

    Amazing sir got it!!

  • @neerajsaini1748
    @neerajsaini1748 2 роки тому +1

    what if opponent is also playing optimally ?

  • @adarshdubey1784
    @adarshdubey1784 2 роки тому +1

    Sir how would we come to know that we have to use gap startegy?

  • @rajanipriyamishra3735
    @rajanipriyamishra3735 2 роки тому

    I came to understand the question, got a life lesson also..lol

    • @Pepcoding
      @Pepcoding  2 роки тому

      for a better experience, use the same content on nados.pepcoding.com

  • @alltechsimplified2134
    @alltechsimplified2134 3 роки тому

    30:38 you are a problem solver and a good singer also :)

  • @aryanyadav3926
    @aryanyadav3926 Рік тому

    Brilliant!

  • @bhavin6431
    @bhavin6431 3 роки тому

    Explaination at its best !!

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @KundanKumar-im1gs
    @KundanKumar-im1gs 2 роки тому

    amazing sir...true knowledge

  • @abhishekdabral_diary
    @abhishekdabral_diary 2 роки тому

    Thanks for this amazing video 👍

  • @abhishekpant5040
    @abhishekpant5040 2 роки тому

    nice explanation

  • @utkarshsharma1185
    @utkarshsharma1185 2 роки тому +1

    thanks sir

  • @prathmeshadsod629
    @prathmeshadsod629 2 роки тому

    Very nice video... Thanks❤

    • @Pepcoding
      @Pepcoding  2 роки тому

      Glad you liked it!
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @jatinbhatoya8420
    @jatinbhatoya8420 3 роки тому

    sir jo even odd wali strategy aapne starting main btayi hai vo iss test case prr fail hai [2,4,55,6,8]

  • @indranilchakraborty5949
    @indranilchakraborty5949 3 роки тому +2

    Legend coder...🙏❤

  • @dakshchaudhary3848
    @dakshchaudhary3848 3 роки тому +1

    Really good explanation!!

  • @raj_kundalia
    @raj_kundalia Рік тому

    thank you!

  • @rupeshsharma9235
    @rupeshsharma9235 3 роки тому +1

    sir some of your videos are not directly accessible through your website. so can you pls fix this issue and thanku so much for this great content

  • @anug14
    @anug14 2 роки тому

    how to solve this through recursion or top down approach.

  • @adityateltia7583
    @adityateltia7583 3 роки тому +3

    Where can we learn about this gap strategy ? Awesome explanation btw :)

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Will upload soon

    • @adityateltia7583
      @adityateltia7583 3 роки тому

      @@Pepcoding ok thankyou sir ! 🙌🏻 will be waiting .

    • @mohitgangwar8120
      @mohitgangwar8120 2 роки тому

      @@Pepcoding need gap strategy

    • @jazzbeat4443
      @jazzbeat4443 2 роки тому

      @@Pepcoding video released sir ? about gap strategy ?

  • @ANILKUMAR-mi5xm
    @ANILKUMAR-mi5xm 3 роки тому

    wow! best video on this topic

  • @JaiSagar7
    @JaiSagar7 2 роки тому

    learn gap strategy and this amazing question💗

    • @Pepcoding
      @Pepcoding  2 роки тому

      For better experience and precisely arranged videos.
      Visit - nados.pepcoding.com and sign up to NADOS.
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @TheBoredandCool
    @TheBoredandCool 3 роки тому

    Thankyou sir, you saved the life.

  • @navneetchaurasia4279
    @navneetchaurasia4279 3 роки тому

    Bacha liya aaj ke interview me
    Pepcoding jindabad😂

    • @Pepcoding
      @Pepcoding  3 роки тому

      wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.

  • @pranjalmishra2602
    @pranjalmishra2602 Рік тому

    life lesson de di sir ne 4:00

  • @Impromptu21
    @Impromptu21 3 роки тому

    Gajab kr diye app to

    • @Pepcoding
      @Pepcoding  3 роки тому

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @munishgarg75
    @munishgarg75 3 роки тому

    Really Awesome Explanation....

    • @Pepcoding
      @Pepcoding  3 роки тому

      Thank you so much and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @kingage4138
    @kingage4138 Рік тому

    Is it similar to matrix chain problem ?

  • @tarekhasan5005
    @tarekhasan5005 3 роки тому +1

    Best explanation.

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Keep learning, Keep growing and keep loving Pepcoding!😊

  • @ani68
    @ani68 2 роки тому +2

    Same logic for stone game....🔥

    • @Pepcoding
      @Pepcoding  2 роки тому +1

      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

    • @raht9578
      @raht9578 2 роки тому +1

      Thats why i came here

  • @AdityaSingh-ql9ke
    @AdityaSingh-ql9ke 2 роки тому +1

    hmm.This is very much like mini max algo...
    And if that's the case..I think we can optimise it using alpha beta pruning.

  • @shreyashachoudhary480
    @shreyashachoudhary480 3 роки тому

    Magic of diagonal of traversal!

  • @anoubhav
    @anoubhav 3 роки тому +2

    Sir, the question link in the description is not there. Thank you for the videos!

  • @balajijangde8470
    @balajijangde8470 2 роки тому

    Sir you are great 👍👍

  • @gauthamganesh2331
    @gauthamganesh2331 2 роки тому

    💓 no words to say

  • @rishurana9655
    @rishurana9655 2 роки тому

    in which lecture sir has taught gap strategy??

  • @CodeSuccessChronicle
    @CodeSuccessChronicle 2 роки тому

    For a moment I checked my WhatsApp web whether it’s mine
    Great explanation like always

  • @ShivamKumar-cv7jv
    @ShivamKumar-cv7jv 3 роки тому +3

    Anyone can tell me in which type of specific question we fill diagonal matrix..

    • @mickyman753
      @mickyman753 3 роки тому +2

      in palindromic susbseq and substring ques , or where we need starting index ele and ending ele of a subarray or substring

  • @anshumansekhardash3666
    @anshumansekhardash3666 3 роки тому

    very good

  • @kartikaymahajan9591
    @kartikaymahajan9591 2 роки тому

    sir gap strategy ki konsi video hai? please reply anyone? and ye questions konsi playlist mei included hai? aapke channel mei dp ki ek hi playlist hai level 1 wali

  • @saurabhgupta9532
    @saurabhgupta9532 3 роки тому

    what is a gap strategy?

  • @peaceandlov
    @peaceandlov 3 роки тому +1

    Legend!!

  • @ayushrajsrivastava9467
    @ayushrajsrivastava9467 3 роки тому

    awesome explanation

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Thanks buddy!
      I am glad you liked it. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc

  • @DEEPANSHUAGGARWAL
    @DEEPANSHUAGGARWAL 3 роки тому

    Most awaited video sirji😂

    • @Pepcoding
      @Pepcoding  3 роки тому +2

      Dekh kar btaie ki samajh aya ya nahi

    • @varsha4260
      @varsha4260 3 роки тому

      @@Pepcoding sir samajh aaya lekin table mei aise ranges baanane ka idea bhi bathao mathlab table ka intuition

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      @@varsha4260 beta koi video dekho jisme gap strategy sikhaya ho

  • @shubhhamkumar6845
    @shubhhamkumar6845 3 роки тому

    Sir, why the gap strategy is used. How do I know where gap strategy can be used for not

    • @mickyman753
      @mickyman753 3 роки тому

      in palindromic susbseq and palindromic substring ques , or where we need starting index ele and ending ele of a subarray or substring at any point

  • @anuragv400
    @anuragv400 3 роки тому

    Its similar to Minimax algorithm from Game Theory !

  • @anilparmar5175
    @anilparmar5175 3 роки тому

    greate sir

  • @dsa3334
    @dsa3334 3 роки тому

    Best Explanation