Patching Array | Thought Process | Dry Runs | GOOGLE | Leetcode 330 | codestorywithMIK

Поділитися
Вставка
  • Опубліковано 14 чер 2024
  • Whatsapp Community Link : www.whatsapp.com/channel/0029...
    This is the 35th Video of our Playlist "Greedy Technique : Popular Interview Problems" by codestorywithMIK
    In this video we will try to solve a very good greedy Problem : Patching Array | Thought Process | Dry Runs | GOOGLE | Leetcode 330 | codestorywithMIK
    I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
    We will do live coding after explanation and see if we are able to pass all the test cases.
    Also, please note that my Github solution link below contains both C++ as well as JAVA code.
    Problem Name : Patching Array | Thought Process | Dry Runs | GOOGLE | Leetcode 330 | codestorywithMIK
    Company Tags : GOOGLE
    My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Intervie...
    Leetcode Link : leetcode.com/problems/patchin...
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My Recursion Concepts Playlist : • Introduction | Recursi...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Subscribe to my channel : / @codestorywithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    Summary :
    Key Concepts:
    Maximum Reach (maxReach):
    maxReach represents the largest sum that can be formed using the current set of numbers from nums and any patches added so far.
    Iterating Through nums:
    We iterate through the nums array to incrementally build up the range of sums that can be formed. If the current number nums[i] is within the next achievable range (less than equal to maxReach + 1), we add it to maxReach and move to the next number.
    Adding Patches:
    Whenever a gap is detected (i.e., nums[i] is greater than maxReach + 1), we add a patch. The most efficient patch is maxReach + 1, which extends the achievable range maximally.
    Loop Until maxReach Covers n:
    The loop continues until maxReach reaches or exceeds n.
    ✨ Timelines✨
    00:00 - Introduction
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024

КОМЕНТАРІ • 91

  • @ankit0225
    @ankit0225 Місяць тому +8

    00:02 Leetcode 330: Patching Array - Solve without fancy data structures
    02:29 Explaining the concept of patching an array by adding elements to form a sequence from 1 to n
    06:38 Patch Missing Array Numbers with 2 or 3
    08:39 Importance of taking smaller numbers for patching arrays
    12:34 Incrementing the maximum reachable number by adding a patch
    14:45 Explanation of Patching Array and Maximum Reachable
    18:23 Understanding maximum reach force in array patching
    20:27 Calculating reach of array elements through Dry Runs
    24:07 Patching strategy based on max reach and current number comparison
    26:18 Explanation of the patching process and reaching the target number.
    30:32 Algorithm for finding max reach and steps in array problem
    Crafted by Merlin AI.

  • @niteshkumarjha7914
    @niteshkumarjha7914 Місяць тому +60

    bhaiya, pls start giving the contests solution as well🙏

  • @akshaychavan5511
    @akshaychavan5511 Місяць тому +10

    This feels like a Math problem. A tough intuition to come up with.

  • @newglobal2056
    @newglobal2056 Місяць тому +28

    Segment tree padha do bhaiya pls ajj bhi 4th wala Q's Nehi hua 😢pls padha do segment tree

  • @vishwashsoni610
    @vishwashsoni610 Місяць тому +16

    Aap k video ka he wait kar raha tha kyu ki subha se sub videos dekh liya koi itne ache se nahi samjhaya tha ... you're the best !!!! ❤

    • @aws_handles
      @aws_handles Місяць тому

      Same bro

    • @SaurabhYadav008
      @SaurabhYadav008 Місяць тому

      Bhai same code maina likha mera saara testcase pass nhi hua?

  • @craftsworld3237
    @craftsworld3237 Місяць тому +2

    Anyone who is thinking how to proove this greedy
    let me give you a proof(or another approach)
    what we will be doing is
    at some index we will be deficit by some number now there may be case we can fulfil by adding number less than required number
    but we may think of adding largest number as possible such that it may help to form more sum as possible ( this may be more greedy approch easy to think)
    for eg
    in 1 2
    we require 4 we can fuillfill by adding 1 only but if we add max number as possible here 4 it may form more sum and my reach our answer as fast as possible
    this can be another approach but code will be same ( sort of proof it is)

  • @rishabhverma9135
    @rishabhverma9135 Місяць тому +1

    Very good explanation. Thank you for uploading this

  • @Thriftinghai
    @Thriftinghai Місяць тому +4

    Thank you for making yet another hard to easy.
    Also please teach segment tree. I like your teaching

  • @nikhilhaspe2734
    @nikhilhaspe2734 15 днів тому +1

    Nice explanation sir ji 🔥🚒

  • @heisenberg6178
    @heisenberg6178 Місяць тому +2

    One of the best channel for dsa

  • @govindlohar6816
    @govindlohar6816 Місяць тому

    nice intuation to thought about question

  • @rahulharsh545
    @rahulharsh545 Місяць тому +1

    woow what a explanation just brilliant

  • @rishabhpanesar9621
    @rishabhpanesar9621 Місяць тому +1

    Superb explanation!

  • @pranavpranjal2717
    @pranavpranjal2717 Місяць тому +2

    bhai ur way is the best among all others!

  • @nirmalgurjar8181
    @nirmalgurjar8181 Місяць тому

    Solved this problem with slightly diff approach but same observation. Thanks for your solution. WE can easily check from below case time complexity : max( O(len), O(logN))
    class Solution {
    public int minPatches(int[] nums, int n) {
    int idx = 0;
    long lookingFor = 1;
    int count = 0;
    while (idx < nums.length && lookingFor lookingFor) {
    count++;
    lookingFor = 2 * lookingFor;
    } else if (nums[idx] < lookingFor) {
    lookingFor = lookingFor + nums[idx];
    idx++;
    } else {
    lookingFor = 2 * lookingFor;
    idx++;
    }
    }
    while (lookingFor

  • @s92885
    @s92885 Місяць тому

    Best explanation for the question!!!

  • @gauravtiwari666
    @gauravtiwari666 Місяць тому +1

    really like the way you elobrate..

  • @anonymous10906
    @anonymous10906 Місяць тому +1

    one of the best ques and best explanation

  • @growingwithtech
    @growingwithtech 29 днів тому

    log(n) here seems to be the best case time complexity when the elements in the array tend to be 0 (they cannot be just tend to 0). Then the loop will always go to else condition.
    However, for worst case time complexity, lets consider nums[i] = {1,1,1,1,1,1} and n=6. Here maxReach will grow linearly with the size of nums array. And hence the worst case time complexity should be O(n).

  • @aashishjhajha1903
    @aashishjhajha1903 Місяць тому +1

    thanks for the video really helpful with great concept 🥰

  • @priyanshkumariitd
    @priyanshkumariitd Місяць тому

    Great Explanation bhaiya as always:) Thanks a lot for this video

  • @gouravkumarshaw5467
    @gouravkumarshaw5467 Місяць тому

    awesome explanation thanks!!

  • @gauravbanerjee2898
    @gauravbanerjee2898 Місяць тому

    Thanks a lot bhaiya ❤❤

  • @aws_handles
    @aws_handles Місяць тому

    Hats off 🙌

  • @YashSinghal
    @YashSinghal Місяць тому +2

    very good Q and Soln

  • @ugcwithaddi
    @ugcwithaddi Місяць тому

    Thanks a lot.

  • @vishalgaurav4193
    @vishalgaurav4193 Місяць тому

    wow bhaiya 🤩, what an explaination from hard to easy. really loved that!!!!❤❤

  • @malavipande6693
    @malavipande6693 Місяць тому

    Thank you❤

  • @shxxxam.thakur
    @shxxxam.thakur Місяць тому +1

    LeetCode: another hard question, will it break your streak today?
    Me : back to back Hard ques might cause me little trouble.
    LeetCode: But would you lose?
    NAH I'D WIN
    DOMAIN EXPANSION🤞 : CodestorywithMIK's explanation!

  • @s78_EditZ
    @s78_EditZ Місяць тому

    thank you ❤❤❤❤❤❤

  • @gagankaushik556
    @gagankaushik556 17 днів тому +1

    thnx 😄

  • @rounaq_khandelwal
    @rounaq_khandelwal Місяць тому +1

    soon to reach 52k subs

  • @AnkitSingh-tm5dp
    @AnkitSingh-tm5dp Місяць тому +2

    Good morning bhaiya

  • @yashkalia2311
    @yashkalia2311 Місяць тому +4

    contest solution please

  • @user-is6pf9gh2r
    @user-is6pf9gh2r Місяць тому

    you made it look so simple , but I messed it before

  • @akmarkan2490
    @akmarkan2490 Місяць тому

    Thanks a kot

  • @Sherlock-xv8mh
    @Sherlock-xv8mh Місяць тому

    Bhaiya please create a complete playlist for learning dsa along with the videos you already have and add a few more videos teaching concepts which you have not yet covered till now. I would have been 10x better in solving problems had I been able to learn complete dsa from you.

  • @rajverma1703
    @rajverma1703 Місяць тому +1

    Plz give the explaination video for problem 3 of today's contest

  • @AnimationVideo338
    @AnimationVideo338 Місяць тому +1

    please also make video for leetcode contest 3rd and 4th questions

  • @minutelearn7663
    @minutelearn7663 Місяць тому +1

    🤩

  • @EB-ot8uu
    @EB-ot8uu 28 днів тому

    legend

  • @upcoming_Engineer_
    @upcoming_Engineer_ Місяць тому +1

    Bhaiya please, segment tree lectures in Cpp and Java.

  • @secretvibz6300
    @secretvibz6300 Місяць тому

    pleasee make a video on segment tree or Finwik tree🙏

  • @adityarathore7744
    @adityarathore7744 Місяць тому

    Bro can you also explain leetcode contest questions?

  • @Dezy_Kri
    @Dezy_Kri Місяць тому +4

    Please provide contest solution

  • @SaurabhYadav008
    @SaurabhYadav008 Місяць тому

    Beautifully explained the concept but this code didn't passed all the testcases. You have to make little changes in it

  • @intelligentprogrammer
    @intelligentprogrammer Місяць тому

    Bhaiya please Solve & explain LC 174. Dungeon Game.
    It is quite tricky 🫡🫡

  • @pranjalyadav4006
    @pranjalyadav4006 Місяць тому

    plz make video on third question leetcode contest 402

  • @parvahuja7618
    @parvahuja7618 Місяць тому +1

    sir how to develop such intuition ?

  • @kartikforwork
    @kartikforwork Місяць тому

    this ques is same as 2952. Minimum Number of Coins to be Added.
    inc ur ques count.

  • @abhishekfulzele6527
    @abhishekfulzele6527 Місяць тому

    where do you work MIK??can we connect on LinkedIN?

  • @mayankshakya9200
    @mayankshakya9200 Місяць тому

    Bhaiya please make a vid on last contest q3 spell wala wo samaj nahi aarha kahi se bhi recursive way nahi karaya kisi ne uska

  • @Rajdweep
    @Rajdweep Місяць тому

    man this qs me i got 0 intuition literally... itne qs kr liya lekin kuch intuition nhi aya qs padke... 🙂 kaise hoga accha company crack

  • @insidious_681
    @insidious_681 Місяць тому

    sir plz provide contest solution
    we all need them
    guys plz like this if u want contest solution

  • @Rajdweep
    @Rajdweep Місяць тому

    segment tree Fenwick tree sikha do boss last 5 6 contests me 4th qs inpe aa rhe hai😢

  • @pokeindia5361
    @pokeindia5361 Місяць тому +1

    Bhaiya please *longest valid parantheses* question bataiye

  • @ManojKrVerma-vw4dx
    @ManojKrVerma-vw4dx Місяць тому

    I was searching for some math here....

  • @rev_krakken70
    @rev_krakken70 Місяць тому

    I completely misinterpreted this question. I thought that patching means replacijg the element rather than inserting at that position

  • @maheshjamdade1
    @maheshjamdade1 Місяць тому

    Please make shorter explanations under 15 minutes

  • @jagdishrathod3299
    @jagdishrathod3299 Місяць тому +1

    Hello i dont understand if condition maxReach+=nums[i];

    • @gui-codes
      @gui-codes Місяць тому +2

      when you include an element nums[i],
      now you can get the sum till maxReach + nums[i] which he showed here from this timestamp - 18:57 se dekho

  • @meme-ku1vs
    @meme-ku1vs Місяць тому +1

    contest solutions please 2 and 3rd

    • @jewelchakraborty9717
      @jewelchakraborty9717 Місяць тому

      /* Solution for ques 2 ---- Contest 403 */
      class Solution {
      public long countCompleteDayPairs(int[] a) {
      int n = a.length;
      long cnt = 0;
      HashMap map = new HashMap();
      for(int i = 0; i < n; i++){
      int r1 = a[i] % 24;
      int r2 = 24 - r1;
      if(r1 == 0){
      cnt += map.getOrDefault(0, 0);
      }
      else if(map.containsKey(r2)){
      cnt += map.get(r2);
      }
      if(map.containsKey(r1)){
      map.put(r1, map.get(r1) + 1);
      }else{
      map.put(r1, 1);
      }
      }
      return cnt;
      }
      }

    • @jewelchakraborty9717
      @jewelchakraborty9717 Місяць тому

      Thought process ----> If (a + b) is divisible by k, then (a % k) + (b % k) is also divisible by k. (31 + 41) % 8 then (7 + 1) % 8. let r1 = (a % k) and r2 = (b % k) then 0

  • @peterfromengland8663
    @peterfromengland8663 Місяць тому

    I wasn't able to solve it on my own .I was like using dp recursion bla bla .. please help will I ever do DSA efficiently on my own.? Sir can you tell us what made you think like this approach 😢😢

    • @jewelchakraborty9717
      @jewelchakraborty9717 Місяць тому

      same for me, i tried using recursion, solved it but got TLE

    • @upcoming_Engineer_
      @upcoming_Engineer_ Місяць тому

      @@jewelchakraborty9717 obviously, as constraints not allow us to use recursion. we need to see for another approach.

    • @jewelchakraborty9717
      @jewelchakraborty9717 Місяць тому

      ​@@upcoming_Engineer_ But how do guys come up with such an efficient solution? I was not able to think even a bit about this optimal solution on my own. Does this come up with practice and experience?

  • @RohitRaj-hl6ji
    @RohitRaj-hl6ji Місяць тому

    Its not intuitive 😢

  • @theindianshady
    @theindianshady Місяць тому

    No voice ?

  • @user-zs8of1yl2v
    @user-zs8of1yl2v Місяць тому +2

    First comment ❤❤🎉, mike bhaiyaa make a whatsapp group for subscribers pls ❤❤❤

    • @gui-codes
      @gui-codes Місяць тому

      description me jo whatsapp link hai uske alawa bhi koi group h kya ?

    • @user-zs8of1yl2v
      @user-zs8of1yl2v 29 днів тому

      @@gui-codes wo whatsapp channel he but me aisa bol rah hu ki aaur ek WhatsApp group chahiye jaha sab log apne idea approch share kar paye questions

  • @AyushKumar-xd5cv
    @AyushKumar-xd5cv Місяць тому +1

    Great 🔥
    Can you please upload today contest q3 🥹