Difference Array Technique | Tutorial | Range Updates | Competitive Programming Tricks Part 1

Поділитися
Вставка
  • Опубліковано 27 лис 2024

КОМЕНТАРІ • 63

  • @PriyanshAgarwal
    @PriyanshAgarwal Рік тому +18

    Here is something you might want to ask yourself after watching this video: What if the initial array given to us is not filled with 0s, would this technique still work? If not, how will you modify it so that it still works.

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

      ​@@nakshatrasharma7183why not add it because it was initially given to us??

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

      We need to modify the array like this:
      for(int i=n-1;i>0;i--){
      arr[i]=arr[i]-arr[i-1];
      }

    • @Mkhuss
      @Mkhuss 7 місяців тому +1

      Just take an array filled with all 0 initially, perform the queries, and you will get the prefix array. After that, add ith value of prefix array to the ith index of the initial array

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

      @@Mkhuss sweet

  • @AbhishekKumar-wx3rw
    @AbhishekKumar-wx3rw 10 днів тому

    the bullet example was great i immediately got why we are doing the process after that example

  • @bitlandsaga
    @bitlandsaga 6 днів тому

    Such a mind-blowing technique. Thanks for such a nice explanation ❤

  • @tinkusharma6274
    @tinkusharma6274 9 днів тому

    Very Helpful, Small video but very efficient..

  • @tarunmali6228
    @tarunmali6228 Рік тому +13

    Please keep bringing similar small videos!!!!

    • @TLE_Eliminators
      @TLE_Eliminators  Рік тому +6

      Yes, a lot of such content is coming up. Stay tuned.

  • @PratikPatil
    @PratikPatil Рік тому +1

    You are growing in your teaching experience

  • @parthchaturvedi9890
    @parthchaturvedi9890 Рік тому +3

    Very informative priyansh, keep posting such videos

  • @harshsankalp2911
    @harshsankalp2911 Рік тому +4

    Hi priyansh, few days ago you posted questions on Time & space complexity on twitter & I was not able to find the right answer. Probably a detailed video on time & space complexity would really help everyone. Also, how to analyse which algorithm would be suitable based on the inputs & constraints. Some standard TC of the loops, how to go about finding the TC & SC etc.

  • @karthick...
    @karthick... Рік тому

    Big fan of you and your work towards indian cp community

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

    Hats off to you man✨️ You explained this technique in a very simple manner✨️

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

    nice concept stored in the tool box.

  • @sagar-tt4ub
    @sagar-tt4ub Рік тому +1

    Good work! Keep the work going. It helps me a lot since I didn't get a place in the tle batch, I study from your youtube videos

  • @RishabhJain-el7hh
    @RishabhJain-el7hh Рік тому

    Bdhiya priyansh bhai, good explanation

  • @juhanchowdhury3907
    @juhanchowdhury3907 Рік тому +1

    This is a wonderful technique 😍

  • @dillibabu1472
    @dillibabu1472 Рік тому +4

    Want more contents like this❤

    • @TLE_Eliminators
      @TLE_Eliminators  Рік тому +3

      Surely, we have planned a series of 5-7 such videos that would be coming up very very soon. Stay tuned.

    • @Josuke217
      @Josuke217 5 місяців тому

      ​@@TLE_Eliminators when will the videos be uploaded?

  • @garvsharma1202
    @garvsharma1202 Рік тому +1

    Thx bro !! for this , please post more content like this

  • @AbhiSingh-jx7bo
    @AbhiSingh-jx7bo Рік тому

    I don't know that this trick is called difference array trick I got to know about this when I solved a CF 1500 rated problem btw it's a beautiful technique and Bhaiya u explained it very well👍

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

    Super bro very useful for us ,we are exict to see these types of videos more ,😍

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

    if the initial array given to us is not filled with 0s we will have a problem because when we create the prefix array we will unnecessarily add or subtract numbers , to avoid this we should already take the difference of the initial adjacent elements . informative video

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

    Very good explanation

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

    useful we need more like this

  • @dudeyouhavenoidea
    @dudeyouhavenoidea 11 днів тому

    THANK YOU !!!

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

    loved it! keep bringing more and thanks

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

    Really very helpful video ❤❤❤😊

  • @JazbaatOfficial07
    @JazbaatOfficial07 Рік тому +1

    Please make these type of amazing content of CP. This will help to many students which are beginner in CP.

    • @TLE_Eliminators
      @TLE_Eliminators  Рік тому +1

      Surely. A lot more is coming. Stay tuned.

    • @insidious_681
      @insidious_681 11 днів тому

      1 0 1 array and do -1 in l = 0 to r = 2; as per this r+1 does not exist

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

    Great video thanks 👍 got at the right time..

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

    Good job 🎉🎉

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

    its parital prefix sum technique

  • @itzzRaghav
    @itzzRaghav Рік тому +3

    Answer of the pinned comment.
    If the initial array is not full of zeroes, there are two things we can do :-
    1. Just create a new array with full of zeroes and do whatever updates we have to do, then atlast when you create its prefix sum array, add the original array values.
    2. But we had to create a new array which is not cool 🙁
    So the other way is to convert that array into the difference array by replacing all values from index 1 to n - 1 by a[i] - a[i-1] and enjoy 🍻.

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

      Perfect. Both will work.

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

      can you make more clear second approach please ?

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

      i guess you should do a[i] = a[i] - a[i-1] starting from i=n-1 to i=1 doing i-- ??

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

      @@amarsharma8582 at the end we are just going to replace a[i] by a[i-1] + a[i], so to reverse it, you can replace it by a[i] by a[i] - a[i - 1]

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

      @@itzzRaghav check this code: is it correct ?
      #include
      #include
      using namespace std;
      int main()
      {
      int n;
      cout > n;
      vector elements(n, 0);
      vector diff(n, 0);
      cout > elements[i];
      }
      int updateValue;
      int l, r;
      cout > updateValue;
      cout > l >> r;
      diff[l] += updateValue;
      if (r + 1 < n)
      diff[r + 1] -= updateValue;
      for (int i = 1; i < n; i++)
      {
      diff[i] += diff[i - 1];
      elements[i] += diff[i];
      }
      cout

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

    interesting trick .............

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

    In 1st problem what exactly we have to do in k queries..
    I am not getting the statement .

    • @SonuKumar-xc1sf
      @SonuKumar-xc1sf Рік тому

      Same, I was excited to know the technique but didn't get the statement of the 1st question which is in description 😢

  • @zero-w1b
    @zero-w1b Рік тому +1

    successfully wasted my 10 minutes. I think everyone knows this technique except beginners

    • @chiragbirla5606
      @chiragbirla5606 Рік тому +5

      Who told you to watch it ??

    • @PriyanshAgarwal
      @PriyanshAgarwal Рік тому +19

      Lol, you watched it despite knowing the technique? The joke is on you then.

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

      why you are wasting your time to comment as well no one cares and no one forcing you to watch.

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

    Amazing content, we need more of this🔥🫡

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

    this trick gave me a nightmare for a few hours. i couldn't understand how someone used this to solve a question in a linear time complexity which is did in O(n * m)