Recursively remove all adjacent duplicates | Recursion | C++

Sdílet
Vložit
  • čas přidán 28. 07. 2024
  • Time Stamps :
    00:00 Problem discussion
    01:55 Approaching the problem
    03:00 Dry Run
    11:33 Code explanation
    13:56 Time Complexity
    Recursion Playlist : • Recursion
    Time Complexity : O(n)
    Space Complexity : O(n)
    Problem Link : www.geeksforgeeks.org/recursi...
    C++ Code Link : github.com/Ayu-99/Data-Struct...
    Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)
    #DataStructuresAndAlgorithms
    #LoveBabbarDSASheet
    #interviewpreparation
    Recursively remove all adjacent duplicates solution
    Recursively remove all adjacent duplicates Leetcode
    Recursively remove all adjacent duplicates C++
    Recursively remove all adjacent duplicates Java
    Recursively remove all adjacent duplicates Python
    Join telegram channel for more updates on placement preparation : t.me/AyushiSharmaDiscussionGroup
    Checkout the series: 🔥🔥🔥
    👉Interview Experiences : • Interview Experiences
    👉 Array: • Arrays
    👉 Linked List : • Linked List
    👉 Recursion : • Recursion
    👉 Stack and Queue : • Stack And Queue
    👉 Greedy : • Greedy
    👉 Dynamic Programming : • Dynamic Programming
    👉 Leetcode contests : • Leetcode contests
    👉 Leetcode June Challenge : • Leetcode June Challenge
    👉 Leetcode July Challenge : • Leetcode July Challenge
    LIKE | SHARE | SUBSCRIBE 🔥🔥😊

Komentáře • 37

  • @xanderash4574
    @xanderash4574 Před 2 lety +5

    mam, the problem which was given and the code u've explained is entirely different....the first example u have taken is "abzxxab"...the output should be "abzab" but not "abzxab"

  • @raghavagrawal6263
    @raghavagrawal6263 Před 2 lety +5

    Hello mam, The first the problem you told in video and the link of which you have given is a little bit different from the one we have solved in this. Please explain the recursive approach for removing all duplicates because in that we have to match with prev one also.

  • @yogeshsikanderpuriya7417
    @yogeshsikanderpuriya7417 Před 2 lety +4

    ayushi the question u reading gfg and the question u r solving on on gfg practice both are different.

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  Před 2 lety +1

      Yes, question is wrong given in practice section in gfg😅

  • @ashutoshshakya5321
    @ashutoshshakya5321 Před 2 lety +3

    but the output is "ay" for input "azxxzy"

  • @sunnykakrani7830
    @sunnykakrani7830 Před 2 lety

    hey ayushi can u pls tell me why my recursive code is giving TLE on GFG .
    string solve(string s,int i,int size)
    {
    if(i==size-1)
    {
    string res="";
    res+=s[i];
    return res;
    }
    string res=solve(s,i+1,size);
    if(res[0]==s[i])
    return res;
    else
    {
    string new_string=s[i]+res;
    return new_string;
    }
    }
    string removeConsecutiveCharacter(string S)
    {
    return solve(S,0,S.size());
    }

  • @ShivRaj00009
    @ShivRaj00009 Před 2 lety

    Really create explanation you made recursion concept very simple by those 3 steps

  • @Swaroop_Rath
    @Swaroop_Rath Před 2 lety

    Hey Ayushi, First of all, thank u so much for such an amazing and quick response. Just one thing I want to mention is, the problem which you have coded on gfg practice is an easy one, but kindly check the one which is given on gfg page itself. It is saying to remove all adjacent duplicates, like complete removal of that character. Eg: i/p: abxxb o/p: a (This is because x is duplicate so completely removed it, then after removing x we are left with the string "abb" so now b is duplicate so completely remove b and then our final string becomes "a" and thus o/p:a).

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  Před 2 lety +1

      Ohh😅, I will try to make video on that asap✌🏻.

    • @Swaroop_Rath
      @Swaroop_Rath Před 2 lety

      @@AyushiSharmaDSA Sure Ayushi... Will be waiting for another extra-ordinary explanation. 😃

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  Před 2 lety +1

      @@Swaroop_Rath 😊thanks

    • @Swaroop_Rath
      @Swaroop_Rath Před 2 lety

      Most welcome 😄

  • @anweshangoswami5636
    @anweshangoswami5636 Před 2 lety

    Hey Aayushi, that's very nicely explained. Just one suggestion:- When you are explaining the code 2nd time on gfg portal, you may rather try explaining by taking the snapshot of the code, paste it in front of the dry run and then explain...maybe that would help us to relate better. But thanks again✌

  • @pycharm_boy4344
    @pycharm_boy4344 Před 2 lety +1

    Very good explanation

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  Před 2 lety +1

      Thank you. 😀 Please share the channel with your friends and juniors 🙏🏻🙌🏻

  • @souravmallick8814
    @souravmallick8814 Před 2 lety

    Thank you.

  • @ranjitkoragoankar
    @ranjitkoragoankar Před 2 lety

    Thank You

  • @akashchourasiya72
    @akashchourasiya72 Před 2 lety

    explain aaa = "" your output is a and i want empty string

  • @RAUSHANKUMAR-iq4yj
    @RAUSHANKUMAR-iq4yj Před 2 lety

    Thanks❤🌹🙏

  • @mrinalmadhav8119
    @mrinalmadhav8119 Před 2 lety

    Mam aap company wise questions lijiye pls

  • @UCSAkhilPrasad
    @UCSAkhilPrasad Před rokem

    Kindly Check the volume. as it is too low

  • @kartikkk4583
    @kartikkk4583 Před 2 lety

    nice explanation

  • @yupp_harish3936
    @yupp_harish3936 Před 2 lety

    hi ayushi i have one doubt

  • @animeshsingh3699
    @animeshsingh3699 Před 2 lety +1

    I tried this way:
    void removeDuplicates(string str, int index, char prev, string &res)
    {
    if(index == str.size())
    return;
    if(str[index] != prev)
    {
    res.push_back(str[index]);
    removeDuplicates(str, index+1, str[index], res);
    }
    else
    removeDuplicates(str, index+1, str[index], res);

    }
    int main()
    {
    string str = "aaaabccdsxx";
    string res="";
    res.push_back(str[0]);
    removeDuplicates(str, 1, str[0], res);
    cout

  • @adolft_official
    @adolft_official Před rokem

    //whats wrong in this code
    class Solution {
    void rem(string &s, int ind){
    if(ind==0)return;
    int val=*s.rbegin();
    s.pop_back();
    rem(s,ind-1);
    if((*s.rbegin())==val)s.pop_back();
    else
    s.push_back(val);
    }
    public:
    string removeDuplicates(string s) {
    int n=s.size();
    rem(s,n-1);
    return s;
    }
    };

  • @deepjyotipator3962
    @deepjyotipator3962 Před 2 lety +2

    Can you please change your video name to exactly which problem you actually solved? You are just misleading by giving name of a hard problem and solving for a basic problem.

  • @yupp_harish3936
    @yupp_harish3936 Před 2 lety

    yar ese q kaise ayenge apne ko

  • @abhisheksamari4591
    @abhisheksamari4591 Před 2 lety

    0.02 seconds solution
    string removeConsecutiveCharacter(string S)
    {
    // code here.
    // int p = 0;
    string str = "";
    char l;
    str+=S[0];
    int p = 1;
    for(int i = 1;i