K-th Symbol in Grammar | Recursion | Recurrence Relation Explained | GOOGLE | Leetcode - 779

Sdílet
Vložit
  • čas přidán 23. 10. 2023
  • Whatsapp Community Link : www.whatsapp.com/channel/0029...
    This is the 1st Video on our Recursion Playlist.
    iPadPDF Notes - github.com/MAZHARMIK/Intervie...
    In this video we will try to solve a strange Recursion Problem - K-th Symbol in Grammar (Leetcode-779).
    There are other ways to solve this problem, if you guys want more solution videos on this problem, kindly let me know through comment.
    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.
    Problem Name : K-th Symbol in Grammar
    Company Tags : GOOGLE
    My solutions on Github : github.com/MAZHARMIK/Intervie...
    Leetcode Link : leetcode.com/problems/k-th-sy...
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Subscribe to my channel : / @codestorywithmik
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    #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

Komentáře • 80

  • @khitijkarmakar
    @khitijkarmakar Před 9 měsíci +14

    i guess recursion is the hardest and the easiest topic simultaneoulsy...jb smjh aata h to kya hi smjh aata ha..aur jb ni aata to poora upar se jata h ....thanks bhaiya

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci

      😇🙏 so true

    • @TrishitChar-wf9qw
      @TrishitChar-wf9qw Před 9 měsíci

      @@codestorywithMIK
      sir please upsolve contest of leetcode && start a series of competitive programming
      I can do medium leetcode but can't do a single in codeforces

    • @aws_handles
      @aws_handles Před 7 měsíci

      True

    • @VivekPathak-ds2do
      @VivekPathak-ds2do Před 5 měsíci

      bhai dil ki baat kah di.

  • @ziauddinzira8248
    @ziauddinzira8248 Před 2 měsíci +1

    Very good teaching with details 😮😊😊😊😊😊😊

  • @ashwindhuriya6598
    @ashwindhuriya6598 Před 9 měsíci +5

    Nobody explains so smoothly like you. When I come to your channel for solution after trying all the ways, I just expect a solution of an EASY question, no matter what is the level of the question on leetcode.😄

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci +1

      Means a lot to me. Thank you so much 😇🙏❤️

  • @dkvFitness
    @dkvFitness Před měsícem +1

    Bro you explained it very well even I watched Aditya verma but didnt understand then I watched yours.Now I completely understood. Thanks bro

  • @astharamwala1057
    @astharamwala1057 Před 3 měsíci

    Muje yahi solution samaj ata he!! Thank you so much for explaining this very well!

  • @tutuimam3381
    @tutuimam3381 Před 9 měsíci +2

    Nice❤❤❤

  • @bossmemes3308
    @bossmemes3308 Před 6 měsíci +1

    My mind after seeing explanation " bhai aapka knowledge to kaamal ka hai" .

  • @souravjoshi2293
    @souravjoshi2293 Před 9 měsíci

    your explanation just blows my mind.

  • @codeandtalk6
    @codeandtalk6 Před 9 měsíci +1

    Best ❤❤❤❤

  • @Thriftinghai
    @Thriftinghai Před 9 měsíci

    Thank you so much for this legit explanation. You are just out of the world

  • @TrishitChar-wf9qw
    @TrishitChar-wf9qw Před 9 měsíci +2

    sir please upsolve contest of leetcode && start a series of competitive programming
    I can do medium leetcode but can't do a single in codeforces

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci

      I am planning soon to start contest videos. Just trying to squeeze time from office and travel plans. Will soon begin.
      Thank you so much for watching 😇🙏

  • @anuppatankar4294
    @anuppatankar4294 Před 9 měsíci

    Great video 💯

  • @aws_handles
    @aws_handles Před 7 měsíci

    Legit explanation man. You are a 💎

  • @umeshbisht1054
    @umeshbisht1054 Před 9 měsíci +2

    Thanku bhaiya ❤

  • @mohithadiyal6083
    @mohithadiyal6083 Před 9 měsíci +1

    Mind blowing explanation 😊

  • @ugcwithaddi
    @ugcwithaddi Před 9 měsíci

    Legit explanation 👌🏻

  • @user-ub2is4rs4x
    @user-ub2is4rs4x Před 9 měsíci

    What a fantastic explanation 🙌🙌

  • @wearevacationuncoverers
    @wearevacationuncoverers Před 9 měsíci

    you are a magician. loved the explanation.

  • @pradip2951
    @pradip2951 Před 7 měsíci +1

    Great Explaination....

  • @JoyAcharyatvl
    @JoyAcharyatvl Před 8 měsíci +1

    best video ever. thank you.

  • @anshukmishra4520
    @anshukmishra4520 Před 9 měsíci +2

    Thank You for helping me out mik bhaiya.

  • @anonymous090
    @anonymous090 Před 9 měsíci +1

    Thank you for the amazing explanation 🥰❤

  • @AnkitSingh-tm5dp
    @AnkitSingh-tm5dp Před 9 měsíci +1

    Brute force hua , Sir I relate problem with bucket water jo abhi past me aya tha also find repeat case etc but unfortunately stuck from last 2 hours thx for today problem 😊😊

  • @code_runner3843
    @code_runner3843 Před 9 měsíci +1

    Done ✅

  • @keertilata20
    @keertilata20 Před 9 měsíci +1

    i was trying to solve it using recursion similar to count and say problem..but this qn was completely different i liked the idea behind this question. Thank you bhaiya understood!

  • @de_coder1
    @de_coder1 Před 9 měsíci +2

    Hey there!
    Your video explanations are damn amazing !!
    I request you to also start making the solutions of the weekly and biweekly leetcode contest solution.
    It will help a lot.

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci +2

      I am planning soon to start contest videos. Just trying to squeeze time from office and travel plans. Will soon begin.
      Thank you so much for watching 😇🙏

  • @PranayMacharla-tu5cn
    @PranayMacharla-tu5cn Před 9 měsíci +1

    I'm solving recursion,dp problems bcoz of ur depth explanation.
    Please provide weekly contest solutions too, it would be greatful .
    Thank u

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci

      I am planning soon to start contest videos. Just trying to squeeze time from office and travel plans. Will soon begin.
      Thank you so much for watching 😇🙏

  • @YashSinghal
    @YashSinghal Před 9 měsíci +1

    amazing how one find such patterns

  • @yadav.nitin03
    @yadav.nitin03 Před 9 měsíci +1

    Yo🎉

  • @atifmirza9168
    @atifmirza9168 Před 9 měsíci +1

    u got a subscriber🤗

  • @sauravchandra10
    @sauravchandra10 Před 9 měsíci

    Didnot understand the part why one half would be the same and the next half would be the complement. If possible, can you make a video using bit manipulation technique.

  • @mohitrathore8808
    @mohitrathore8808 Před 9 měsíci +1

    I was able to do brute force, also tried to solve using recursion after reading that the current solution was dependent on previous one, but unable to write the recursive function parameter for 'n' and 'k.
    Loved your solution ❣

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci

      Thank you for watching 😇🙏

    • @harshtiwari416
      @harshtiwari416 Před 9 měsíci

      can you share brute force here???

    • @sureshchelani7497
      @sureshchelani7497 Před 9 měsíci +1

      @@harshtiwari416
      this is the brute force: but not accepted give TLE->
      class Solution {
      public:
      int kthGrammar(int n, int k) {
      vectorarr(n,vector());
      arr[0].push_back('0');
      for (int i = 1; i < n; i++){
      for (int j = 0; j < arr[i-1].size(); j++){
      if (arr[i-1][j] == '0'){
      arr[i].push_back('0');
      arr[i].push_back('1');
      }
      else{
      arr[i].push_back('1');
      arr[i].push_back('0');
      }
      }
      }
      return arr[n-1][k-1] - '0';
      }
      };

    • @lofireverbz-wy7go
      @lofireverbz-wy7go Před 9 měsíci

      you can see it in discuss section of leetcode@@harshtiwari416

  • @lofireverbz-wy7go
    @lofireverbz-wy7go Před 9 měsíci

    bhaiya i am facing problem in converting the memorization code into tabulation so to understand properly to convert it into tabulation which video of your dp playlist should i watch?
    btw understood today recursion intuition :)

  • @abc-ym4zs
    @abc-ym4zs Před 9 měsíci

    bhaiya i want your suggestion i am not understanding dev topics (backend) and also not able to solve new problems and along this i have to manage college studies feeling overwhelmed in this situation what should i do any suggestion

  • @devkumar9889
    @devkumar9889 Před 9 měsíci +1

    I came up with same observations, but could not think of recursion instead directly did with loop
    Please upsolve contests also it would be helpful

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci +2

      I am planning soon to start contest videos. Just trying to squeeze time from office and travel plans. Will soon begin.
      Thank you so much for watching 😇🙏

    • @devkumar9889
      @devkumar9889 Před 9 měsíci

      @@codestorywithMIK Thanks for yr effort

  • @dhairyachauhan6622
    @dhairyachauhan6622 Před 9 měsíci +2

    did on my own this was kinda similar to 799. Champagne Tower :p
    not the logic but the intuition yes :)
    i would encourage people to solve that too after this question.
    My solution is a bit different
    class Solution {
    public:
    int solve(int n,int k){
    if(n == 0){
    return 0;
    }
    int prevChar = solve(n-1,k/2);
    if(prevChar == 0){
    if(k%2 == 0){
    return 0;
    }
    else{
    return 1;
    }
    }
    if(prevChar == 1){
    if(k%2 == 0){
    return 1;
    }
    else{
    return 0;
    }
    }
    return -1;
    }
    int kthGrammar(int n, int k) {
    return solve(n,k-1);
    }
    };

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci

      Thanks a lot 😇🙏

    • @TrishitChar-wf9qw
      @TrishitChar-wf9qw Před 9 měsíci +1

      @@codestorywithMIK sir please upsolve contest of leetcode && start a series of competitive P
      I can do medium leetcode but can't do a single in codeforces

  • @akashkumarmaurya2319
    @akashkumarmaurya2319 Před 9 měsíci +1

    how did u approach and should we start with some dry run on copy first

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci

      Yes always do some copy work first. It helps to figure out and understand qn

  • @abhijeetsingh7321
    @abhijeetsingh7321 Před 9 měsíci +1

    Bhaiya hmko ye thora thora campaign tower jaisa lag rha hai .... Kya hm sahi soch rhe hai, kyuki abhi hm ye question try nhi kiye hai

  • @crazyduniya128
    @crazyduniya128 Před 9 měsíci +1

    bhaiya contest solutions ki videos bhi upload kr diya kro please

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci +1

      I am planning soon to start contest videos. Just trying to squeeze time from office and travel plans. Will soon begin.
      Thank you so much for watching 😇🙏

  • @aayush0606
    @aayush0606 Před 9 měsíci +1

    another solution :
    int kthGrammar(int n, int k) {
    if(n==1 || k==1) return 0;
    int prev= kthGrammar(n-1,(k+1)/2);
    if(prev==1) return k%2?1:0;
    return k%2?0:1;
    }

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Před 9 měsíci +1

    public class kthGrammar (int n,int k){
    if(n==1) return 0;
    if(k%2==i)
    return kthGrammar (n-1,(k+1)/2)==0?0:1;
    return (n-1,k/2)==0?1:0;
    bits
    int count =Integer.bitCount(k-1)
    return count %2==0?0:1;

  • @shahrohit01
    @shahrohit01 Před 9 měsíci +1

    Three Lines of code :
    int kthGrammar(int n, int k) {
    if(n == 1 && k == 1) return 0;
    int ans = kthGrammar(n - 1, (k + 1) / 2);
    return (k % 2 == 0)? !ans : ans;
    }

  • @tsukuruuu
    @tsukuruuu Před 9 měsíci +1

    class Solution {
    public:
    int f(int n, int k ){
    if(n == 1){
    return 0;
    }

    int temp = f(n-1,(k+1) / 2);
    if(temp == 1){
    if(k%2 == 0){
    return 0;
    }
    return 1;
    }
    else{
    if(k%2 == 0){
    return 1;
    }
    return 0;
    }
    }
    int kthGrammar(int n, int k) {
    return f(n,k);
    }
    };

  • @parthbhatti4151
    @parthbhatti4151 Před 9 měsíci +1

    bro please provide notes

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci

      Sure thing. I have added the PDF link in the Description. YOu can click this below as well
      iPadPDF Notes - github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad%20PDF%20Notes/Leetcode-779-K-th%20Symbol%20in%20Grammar.pdf
      Thank you

  • @Lucifer0872
    @Lucifer0872 Před 9 měsíci +1

    No sound

  • @rogertech9535
    @rogertech9535 Před 9 měsíci +1

    should i solve leetcode daily with college exams

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci +1

      Hi there,
      First get prepared well for exams. If you get time , then only solve leetcode.
      Else, you can continue leetcode post exams. Because good grades are helpful in many companies hiring.

    • @rogertech9535
      @rogertech9535 Před 9 měsíci

      I maintained the consistency of 3 months

  • @39_jatinjain4
    @39_jatinjain4 Před 9 měsíci +1

    I had observed the pattern but unable to write recurrence 🥲🥲

    • @daffi-ko4xn
      @daffi-ko4xn Před 9 měsíci +1

      that is true , we can observe the pattern but unable to write recurrence relation. @codestorywithMIK sir can you please why this happens? please reply sir !!!!!!!!!!!!!!!!!

    • @codestorywithMIK
      @codestorywithMIK  Před 9 měsíci +2

      Hey,
      Actually this happens in some of the problems to me also. So in my case, i usually do a dry run of 2-3 test cases to figure out if the code works. Or what is missing.
      Doing a dry run is also expected in interviews. When you write a code, you must double check with 1-2 examples dry run. It will give you extra points as well in interviews.