Check whether a string is a valid shuffle of two strings or not | Love Babbar DSA Sheet | Amazon🔥

Sdílet
Vložit
  • čas přidán 20. 11. 2020
  • #competitiveprogramming #dsasheet #interviewpreparation
    In this video I have solved the problem of the sheet i.e. Check whether a string is a valid shuffle of two strings or not.
    Complete Explaination with code.
    String question Playlist = • Love Babbar DSA 450 Qu...
    Array question Playlist = • Love Babbar DSA 450 Qu...
    Love Babbar DSA Sheet : drive.google.com/file/d/1FMdN...
    Hope you like it. Comment if you have any doubt
    LIKE | SHARE | SUBSCRIBE

Komentáře • 78

  • @manavkapur8428
    @manavkapur8428 Před 2 lety +6

    aabcc dbbca aadbcbbcac not working for this test case!! Here for last case we will have c and ca now algo will select c first then will go for c in next string but then it will give us error

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

    thanks bro ! very good explanation.

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

    Bro great job keep continuing✌️✌️

  • @tridevthakur5397
    @tridevthakur5397 Před 3 lety

    Excellent task! Hats off😊

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

    actually like we matched s1 first and then s2, likewise we should also look for matching s2 first then s1. If either of this satisfies both the strings then answer is true. eg. take s1 = xy, s2 = zyb and res = xzyby. if we match elements of s1 first then it would return false.

  • @Ganesh-du8sw
    @Ganesh-du8sw Před 3 lety +12

    i would like to suggest you one thing that you should have to start from worst case to best case for every solution because it will help to beginner
    they will understand the meaning of optimization

  • @DurgaShiva7574
    @DurgaShiva7574 Před 2 lety

    behtareeen !!!

  • @108_adityakumar6
    @108_adityakumar6 Před 2 lety +8

    Interleaved string on leetcode and this problem both are same.I think there is no any two pointer approach to this problem.It can be solved by only using Dynamic programming.Two pointer would not be able to handle a lot of cases.

    • @imranwahid9871
      @imranwahid9871 Před rokem +1

      Exactly. The solution, he explained is wrong. It won't cover all the test cases.

  • @DeepakKumar-nk3cv
    @DeepakKumar-nk3cv Před 2 lety +1

    Great content

  • @ayeshaadhikari6123
    @ayeshaadhikari6123 Před 3 lety

    thank you bhaiya :)

  • @anshulvairagade1604
    @anshulvairagade1604 Před 3 lety +3

    Thanks you so much
    You are doing a very good job !

  • @codeshahar
    @codeshahar Před 3 lety +5

    Bro, Why you haven't used f for final check ?

  • @ROSHANKUMAR-rl6bf
    @ROSHANKUMAR-rl6bf Před 3 lety +2

    why and how is it diffrent from interleaving problem please reply

  • @animeshjain8569
    @animeshjain8569 Před 3 lety +1

    Buggy code a1 and a2 and resultant string is a2a1.i points to string a1 and j to a2

  • @tanmaymalhotra4450
    @tanmaymalhotra4450 Před 3 lety

    well explained,thanks!

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

    Can somone please explain how the 'f ' variable was helpful in the code??

  • @gouravmalik6829
    @gouravmalik6829 Před rokem +1

    bro ye code sirf distinct characters par kaam krega agr A ya B me elements repeat hogye toh fail ho jayega

  • @ranjeet5806
    @ranjeet5806 Před 3 lety

    bhai thnx for such a great video. one thing that caught my attention was the flow of your speaking became so good after switching to Hinglish. Thank you.

  • @mustafandf
    @mustafandf Před 2 lety +11

    If s1 = "ab", s2 = "abb" and res="abbab"....
    This logic fails...

    • @okiedokie8303
      @okiedokie8303 Před 2 lety

      watch 1:20 ,the condition is that we cannot shuffel the order .

    • @subhajitghosh8349
      @subhajitghosh8349 Před 2 lety

      bro this is not suffel in correct order. "bb" will come always after a

    • @jaygoyani5934
      @jaygoyani5934 Před rokem

      you are right in coding ninja plt this logic is not enough

  • @dreamarena5312
    @dreamarena5312 Před 3 lety

    Nice
    But what is the use of f

  • @RahulSharma-wn1ty
    @RahulSharma-wn1ty Před 3 lety

    thanks..int f=0; is not required

  • @lokeshnegi5051
    @lokeshnegi5051 Před 3 lety +1

    bro but where is brute and optimal.

  • @Selim_Hasan_Raj
    @Selim_Hasan_Raj Před rokem

    does the order matter?

  • @rahulvig5298
    @rahulvig5298 Před rokem

    Same characters ke liye nahi chalega ye code. But explanation achi thi bhai. Thanks

  • @rohitprajapati1253
    @rohitprajapati1253 Před rokem

    above solution is failed for the given string a = aabd , b = abdc , c= aabdabcd output is No but correct is "Yes"

  • @ROSHANKUMAR-rl6bf
    @ROSHANKUMAR-rl6bf Před 3 lety +1

    aab axy aaxaby for this tet case ur code gives wrong ans

  • @GauravSharma-gi4nc
    @GauravSharma-gi4nc Před 2 lety +1

    Hey bro I don't think it will work for every testcase
    for ex str1="AAAAABAA" .,str2="AAAB" str3="AAABAAAAABAA"

  • @chanduchandrakanth5131

    Then y did you taken f

  • @roshanraut3093
    @roshanraut3093 Před 3 lety +4

    Wrong Logic Fails for Test:
    ab12 and abb34 are two strings, then abbab1234

    • @psriakhil3347
      @psriakhil3347 Před 3 lety +1

      This logic is for two distinct strings.

    • @farhanalam3876
      @farhanalam3876 Před 3 lety +1

      Use DP.

    • @KAMMARANJANIKPES
      @KAMMARANJANIKPES Před 2 lety

      try this it's my logic:
      #include
      using namespace std;
      #include
      bool help(string s1, string s2, string s){
      int i=s1.length();
      int j=s2.length();
      int k=s.length();
      if(i+j!=k)
      return false;
      i=0;
      j=0;
      k=0;
      while(k>s2>>s;
      cout

    • @justarandomguy6106
      @justarandomguy6106 Před 2 lety

      Then how did you sove it, plz give ur code

  • @igautammunot8714
    @igautammunot8714 Před rokem

    code will fail for test case : "s1 : aabd, s2 : abdc, res : aabdabcd"
    this is interleaved strings problem which can be solved using dp

  • @siddharthsahu8763
    @siddharthsahu8763 Před 3 lety

    Time Complexity O(n)?

  • @hritikrawat6452
    @hritikrawat6452 Před rokem

    It's not run for all the test cases

  • @vishwajeetchoudhary270

    That's not the complete code , it won't outputs correct answer for unsorted string .

  • @deepanshukumar7290
    @deepanshukumar7290 Před 3 lety

    bro matrix ke bhi video banao aur array ke pending videos

    • @CodeLibrary
      @CodeLibrary  Před 3 lety +3

      First I was trying to solve important questions then after that I will be posting remaining questions 😀

    • @deepanshukumar7290
      @deepanshukumar7290 Před 3 lety

      @@CodeLibrary okay bro !!!

  • @nehalpradhan2229
    @nehalpradhan2229 Před rokem

    i think you forgot to mention that this method does not work for strings with duplicate characters. and f variable is useless.

  • @jaygoyani5934
    @jaygoyani5934 Před rokem

    can anyone send right solution ??

  • @vedanshudhawani6865
    @vedanshudhawani6865 Před rokem

    Pehle sort karna padenga sab strings ko tabhi chalenga ye approach..

  • @AbhishekKumar-wx3rw
    @AbhishekKumar-wx3rw Před rokem

    the solution is wrong for s1 = "aabd" s2 = "abdc" and res = "aabdabcd"

  • @amishamohapatra9977
    @amishamohapatra9977 Před 3 lety +1

    bhaiya yahna pe f variable ka koi need hi nahi hai na?

  • @gaganbaghel8754
    @gaganbaghel8754 Před 2 lety

    source code

  • @YashSharma-dz7uu
    @YashSharma-dz7uu Před rokem

    using dynamic + memoization
    bool f(string &a,string &b,string &c,int i,int j,int k,vector&dp){
    if(i==a.size() && j==b.size() && k==c.size()) return true;
    if(dp[i][j]!=-1) return dp[i][j];
    bool ans;
    if((i

  • @71_rahulnair86
    @71_rahulnair86 Před 3 lety +4

    aab axy aaxaby bhai iss condition mai code error dega

    • @CodeLibrary
      @CodeLibrary  Před 3 lety +4

      This code will work for distinct characters....... If repeating characters are allowed then we have to check all possibilities and we have to use DP.....one question is their in DP section of sheet ...when I will solve dp section then I will explain that

  • @prakhargarg4166
    @prakhargarg4166 Před 6 měsíci

    why f variable

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

    wrong solution use dp

  • @kushagragupta5925
    @kushagragupta5925 Před 2 lety

    Sorry to say but your solution is wrong as you are neglecting the case when s1[i]== s2[j] and you are prioritising s1 there. Take two strings as "demno" , "abdefmn" and resulting string as "abdedfemnmon". You cannot get the correct output if you are prioritising one string over other. Try string1 as "demno" or string2 as "demno" both ways you will fail but this testcase is a valid shuffle. Please change your solution.

    • @rahulvig5298
      @rahulvig5298 Před rokem

      Right. Sorting is required of the 3 strings before comparing.

  • @Rohitkumar-hj3wq
    @Rohitkumar-hj3wq Před 2 lety

    wrong explanation in this question order does not matter of s1 and s2 in s3.

  • @swetathakur2873
    @swetathakur2873 Před 8 měsíci

    f ka zrurat nhi tha !

  • @manasvinsharma1740
    @manasvinsharma1740 Před 3 lety

    Question hi change krdia... Babbar dsa sheet m ye thodi hai 🙄😶

  • @manishdharmani4695
    @manishdharmani4695 Před 2 lety

    Are bhai tujhe train pakadni hoti h kya... Aaram se bta diya kr thoda