Shifting Letters II | Leetcode 2381 | Difference Array Technique: Concepts & Questions - 2 | MIK

Поделиться
HTML-код
  • Опубликовано: 20 янв 2025

Комментарии • 60

  • @codewith_me07
    @codewith_me07 16 дней назад +22

    Thank you sir jo aapne isse pehle wali video upload ki thi usi concept se mene ye problem solve kr li

    • @codewith_me07
      @codewith_me07 16 дней назад +3

      class Solution {
      public String shiftingLetters(String str, int[][] shifts) {
      StringBuilder ans = new StringBuilder();
      int []pre = new int[str.length()];
      for(int arr[] : shifts){
      int s=arr[0];
      int e=arr[1];
      int d=arr[2];
      if(d==0){
      pre[arr[0]]--;
      if(arr[1]+1

    • @gui-codes
      @gui-codes 16 дней назад +3

      same bhai

    • @codestorywithMIK
      @codestorywithMIK  16 дней назад +5

      ❤️🔥

  • @ToonDubberDuo
    @ToonDubberDuo 16 дней назад +1

    thank you, i could code it watching your intuition from the other video and taking ideas from other's code

  • @CODEWITHEASE-u8l
    @CODEWITHEASE-u8l 16 дней назад +4

    bas aaj ke baad kabhi difference array technique wali problems mei TLE nahi khaunga thank you so much🙏

  • @SudhanshuSingh-jn2lw
    @SudhanshuSingh-jn2lw 16 дней назад +3

    Thanks a lot. Difference array technique is crystal clear now.

  • @aryansinha1818
    @aryansinha1818 16 дней назад +2

    Sometimes after so much effort put into thinking how to solve the potd, and then watching your solution feels like, thank you God for his(your) existence. Really man thank you. btw motivation in the beginning, something which was very much needed. Love and respect always.

    • @codestorywithMIK
      @codestorywithMIK  16 дней назад +1

      I’m glad you enjoyed the video! Thanks for the kind words. 🙏

  • @bhuppidhamii
    @bhuppidhamii 16 дней назад +1

    Choti se choti chiz, aapne itne aache se samzaya h, bhaiya.
    Lots of love 💗

  • @AmandeepSingh-uq3wp
    @AmandeepSingh-uq3wp 16 дней назад +4

    Sharing code of Shifting Letter I and II (If someone wants to see) :
    Shifting Letters | :
    class Solution {
    public:
    string shiftingLetters(string s, vector& shifts) {
    int n = s.size();
    vector rangeUpdates(n + 1, 0);
    int q = shifts.size();

    for (int i = 0; i < q; i++) {
    int start = 0;
    int end = i;
    int value = shifts[i];

    rangeUpdates[start] += value;
    if (end + 1 < n) {
    rangeUpdates[end + 1] -= value;
    }
    }

    long long sum = 0;
    for (int i = 0; i < n; i++) {
    sum += rangeUpdates[i];
    sum = (sum % 26 + 26) % 26;
    s[i] = (s[i] - 'a' + sum) % 26 + 'a';
    }

    return s;
    }
    };
    Shifting Letters || :
    class Solution {
    public:
    string shiftingLetters(string s, vector& shifts) {
    int n = s.size();
    vector rangeUpdates(n + 1, 0);
    int q = shifts.size();

    for (int i = 0; i < q; i++) {
    int start = shifts[i][0];
    int end = shifts[i][1];
    int direction = shifts[i][2];

    rangeUpdates[start] += (direction == 1 ? 1 : -1);
    if (end + 1 < n) {
    rangeUpdates[end + 1] -= (direction == 1 ? 1 : -1);
    }
    }

    long long sum = 0;
    for (int i = 0; i < n; i++) {
    sum += rangeUpdates[i];
    sum = (sum % 26 + 26) % 26;
    s[i] = (s[i] - 'a' + sum) % 26 + 'a';
    }

    return s;
    }
    };

  • @Sachinraj_143-king
    @Sachinraj_143-king 16 дней назад +1

    Thank u sir apke approach too good ❤❤

  • @Ankitkumar-fz3kc
    @Ankitkumar-fz3kc 16 дней назад +1

    Thanks, I already have solved the problem. Just came here to keep up my consistent and learn something new.

  • @kanavbansal450
    @kanavbansal450 16 дней назад +6

    Very helpful bhaiya ❤

  • @Coder_Buzz07
    @Coder_Buzz07 16 дней назад +4

    Lovely motivation bhaiya ❤❤

  • @anuragprajapati3712
    @anuragprajapati3712 16 дней назад +1

    Bhaiya apka channel bahut underrated hai , your channel deserves millions subscribers❤❤

  • @bhuppidhamii
    @bhuppidhamii 16 дней назад +1

    MIK you're awesome 😎

  • @hana_0712
    @hana_0712 16 дней назад +1

    Thank you for today's lecture.

  • @nikhilsoni8840
    @nikhilsoni8840 16 дней назад +2

    bhaiyya you are having long videos but are worth watching🤟💯

  • @SaurabhSinghyadav-r4y
    @SaurabhSinghyadav-r4y 16 дней назад +1

    Sloved this question using brute force approach and 37/39 testcases passed.

  • @gui-codes
    @gui-codes 16 дней назад

    I solved Leetcode-370 also and this problem also after watching the first video of this playlist. I never knew about Difference Array Technique, all thanks to you LEGEND MIK

  • @nikhilsoni8840
    @nikhilsoni8840 16 дней назад +2

    bhaiya, i was searching for your video since morning to solve POTD !!

  • @Nitinrautindore
    @Nitinrautindore 15 дней назад +2

    Sir weekly aur bi-weekly contest ke solutions bhi bna diya karo ❤

  • @krishangaur8877
    @krishangaur8877 16 дней назад +3

    Thanks bhai ❤❤

  • @vishwashsoni610
    @vishwashsoni610 16 дней назад +2

    sir this is how solved today's POTD question after watching your intuition video :
    class Solution {
    public:
    string shiftingLetters(string s, vector& shifts) {
    int n = s.size();
    vectorvec(n,0);
    for(auto& shift : shifts){
    int left = shift[0];
    int right = shift[1];
    int x = shift[2];
    if(x == 1){
    vec[left] += 1;
    if(right + 1 < n){
    vec[right+1] += -1;
    }
    }
    else{
    vec[left] += -1;
    if(right + 1 < n){
    vec[right+1] += 1;
    }
    }
    }
    for(int i=1;i

  • @imPriyansh77
    @imPriyansh77 16 дней назад +1

    Thank you for uploading

  • @k-CE-OmkarPathak
    @k-CE-OmkarPathak 16 дней назад +1

    Thanks

  • @aadityaraj2397
    @aadityaraj2397 16 дней назад +3

    1943 que leetcode , is exactly difference array techinque question 😊

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 16 дней назад +2

    First 🎉❤

  • @indianengineer5802
    @indianengineer5802 16 дней назад

    6:20 indirectly kar toh hum update hee rhe hain na string ki value ko usko backward and forward move karke ?

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 16 дней назад +1

    We can call line sweep algorithm

    • @Zoro_tao
      @Zoro_tao 16 дней назад

      yeah need this one ASAP....

  • @DineshKumar-gt7xm
    @DineshKumar-gt7xm 16 дней назад

    Sir, please make an explanation video on Todays 3rd leetcode contest problem. At first it looks like the difference array problem but a harder one I guess.

  • @abhayshukla5175
    @abhayshukla5175 16 дней назад

    bhaiya please cover concept like rolling hash

  • @OtakRajCodes
    @OtakRajCodes 16 дней назад +2

    Here is the similar java code :
    class Solution {
    public String shiftingLetters(String s, int[][] shifts) {
    int n = s.length();
    int diff[] = new int[n];

    for(int shift[] : shifts){
    int left = shift[0];
    int right = shift[1];
    int x = shift[2] == 1 ? 1 : -1;
    diff[left] += x;
    if(right+1 < n){
    diff[right+1] -= x;
    }
    }
    // find cumilative sum
    for(int i=1;i

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 16 дней назад +1

    public String shiftingLetters(String s,int[][]shifts){
    char[]c=s.toCharArray();
    int n=c.length;
    int[]diff=new int[n];
    for(int[]shift:shifts){
    if(shift[2]==0){
    diff[shift[0]]--;
    if(shift[1]+1

  • @ShardulPrabhu
    @ShardulPrabhu 16 дней назад +3

    cat lover❤attendance 🐈‍⬛🐈

  • @RITIK-z1f1m
    @RITIK-z1f1m 16 дней назад

    Bhaiya please make a video on leetcode biweekly 147 question number 3(Longest Subsequence with decreasing adjacent difference) 🙏

  • @prajwalshaw9217
    @prajwalshaw9217 16 дней назад

    Sir can u add links of other similar questions on topic from leetcode/gfg in the description. It would be really helpful.

  • @VineetDixit
    @VineetDixit 16 дней назад +1

    I HAVE A TWO PASS SOLUTION FOR THIS PLEASE REFER TO THIS,
    int n = s.size();
    vector diff(n , 0);
    for (auto& q : shifts) {
    int direction = q[2] == 0 ? -1 : 1;
    diff[q[0]] += direction;
    if (q[1] + 1 < n) {
    diff[q[1] + 1] -= direction;
    }
    }
    int shift = 0;
    for (int i = 0; i < n; ++i) {
    shift += diff[i];
    int effectiveShift = (shift % 26 + 26) % 26;
    s[i] = 'a' + (s[i] - 'a' + effectiveShift) % 26;
    }
    return s;

  • @nawazthezaifre8870
    @nawazthezaifre8870 16 дней назад

    sir ye aap ek hi video me bhi bata sakte the na where there is need of separate video. Because this video entirely dependent on the first video that's why I'm saying. ab mujhe copy and past karke code submit karna pada is reason se

  • @DarkDragon-bz6qp
    @DarkDragon-bz6qp 16 дней назад

    Nice thumbnail

  • @P_elaxctor
    @P_elaxctor 16 дней назад

    bhaiya leetcode q-43 explain kardo easy way me

  • @amanrajsingh4419
    @amanrajsingh4419 16 дней назад +1

    bhaiya beginner hu abhi dsa kar raha hu daily problem solve karu abhi ya phir dsa karne ke baad start karu

    • @codestorywithMIK
      @codestorywithMIK  16 дней назад +2

      Start by studying concepts first and build fundamentals.
      Always remember that we must study DSA topic by topic . First study the topic’s concepts, then solve good Questions on them. Then move to next topic and so on.
      I usually create two playlists for every topic :
      1) Concepts Playlist - Contains from basic concepts to expert concepts.
      2) Popular Interview Problems playlist.
      I have created concepts and interview problems playlist for
      1) Graph
      2) Recursion
      3) DP
      4) Segment Tree
      Planning soon to create concepts playlist for Tree as well.
      Graph Concepts - ruclips.net/p/PLpIkg8OmuX-LZB9jYzbbZchk277H5CbdY&si=lZG2IJTmSW4kRrx-
      Graph Popular Interview Problems - ruclips.net/p/PLpIkg8OmuX-I_49pdy1XFY6OcATnxUrrO&si=CG2JvGWVmvoSqvWA
      Recursion Concepts - ruclips.net/p/PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM&si=614iI4NyHY-FTeJH
      Recursion Problems (In progress) - ruclips.net/p/PLpIkg8OmuX-IXOgDP_YYiJFqfCFKFBDkO&si=88fBhRnr62OYTnDP
      DP Concepts (In progress) - ruclips.net/p/PLpIkg8OmuX-JhFpkhgrAwZRtukO0SkwAt&si=laFVYy6ep2BkOg0s
      DP Popular interview problems - ruclips.net/p/PLpIkg8OmuX-L_QqcKB5abYynQbonaNcq3&si=VHEn9b-wqTnAVyyi
      Segment Tree Concepts -
      ruclips.net/p/PLpIkg8OmuX-K1qUIQToCllUO0UIKXt8dB&si=xm7DqRN4H0eZwna4
      Difference Array Technique : Concepts & Qns - ruclips.net/p/PLpIkg8OmuX-Kqkb8DqDe_4-Tiav6ilS_L&si=uLVaa_-YYretZUzE

    • @amanrajsingh4419
      @amanrajsingh4419 15 дней назад

      @codestorywithMIK thanks bhaiya ☺️

  • @bhupendrakalal1727
    @bhupendrakalal1727 16 дней назад

    sir kya aap please contest k solutions bhi la skte h kya , aapke alawa kisi aur se samaj hi nhi aaata h??????????????

  • @priyajaiwal8072
    @priyajaiwal8072 16 дней назад +1

    Sundar++

  • @cricketsureshlucky
    @cricketsureshlucky 16 дней назад

    I couldn't figure the answer for contest 3rd question please make a video sit😊

    • @ananyeagarwal9770
      @ananyeagarwal9770 16 дней назад

      Leetcode Contest video solution in case you want - ruclips.net/video/LhsqM-9-gNk/видео.html&ab_channel=KumarK%5BAmazon%5D .

  • @Sachinraj_143-king
    @Sachinraj_143-king 16 дней назад

    Sir In recent contest (weekly contest 431) , leetcode 3413, difference array technique se solve kr rha hu toh memory exceed de rha ...app ek video ye question pe bna dete toh kaffi help ho jatta

  • @GovindLohar-p9e
    @GovindLohar-p9e 16 дней назад

    but sir only the problem is that from youside eveything is ok but i have been solving leedcode from 1 and half year till now i am not able to solve contest question 3 and 4

  • @parthh3963
    @parthh3963 16 дней назад

    1st video ka link?

    • @codestorywithMIK
      @codestorywithMIK  16 дней назад

      ruclips.net/video/ZHNVmtm08WY/видео.htmlsi=B2-5JyTwLbhdcSij
      ❤️

  • @e_sumit
    @e_sumit 16 дней назад +1

    i was searching for your video, before you upload it🫣thanks

  • @joydeep-halder
    @joydeep-halder 16 дней назад +1

    Thank you so much bhaiya for this awesome new technique. ❤🫡
    In last, to map index, I had used this.
    for(int i=0; i