Recursion - Level 1 Questions (Theory + Code + Tips)

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

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

  • @KunalKushwaha
    @KunalKushwaha  2 месяца назад +8

    DSA + interview preparation playlist: ruclips.net/p/PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ

  • @aqsa537
    @aqsa537 2 года назад +402

    Just the intro to recursion video was enough to solve all the questions in this video! I'm a beginner to recursion and felt like I've been doing this for months!
    *For people watching in future blindly trust this bootcamp!*

    • @KunalKushwaha
      @KunalKushwaha  2 года назад +51

      You're very welcome!

    • @shreyasingh4680
      @shreyasingh4680 2 года назад +16

      @@KunalKushwaha we can count 0 without helper function
      int cntz(int n)
      {
      if(n%10==n)
      return 0;
      if(n%10==0)
      return cntz(n/10)+1;
      else
      return cntz(n/10);
      }actually i am learning c++but in order to understand the approach i am here and its just amazing. thank u!

    • @venkateswararaothotakura945
      @venkateswararaothotakura945 2 года назад +3

      @@shreyasingh4680 cntz(int n, c)
      If(n%10==n)
      return 0;
      rem=n%10;
      if(rem==0)
      return(n/10, c=c+1);
      return (n/10) ;

    • @Rajdweep
      @Rajdweep 2 года назад +1

      @@KunalKushwaha one qs bro if we r keeping the function void why are we taking extra functions extra variables etc?cant we just print n%10 and then write func(n/10) in the else part?i tried it and its giving same output in much less steps.

    • @shreyasgosavi9647
      @shreyasgosavi9647 2 года назад

      ​@@Rajdweep Recursive problems can be solved in different ways, there is no single way to solve it. What's important is understanding the concept !!!🙌

  • @piyushkhandelwal1662
    @piyushkhandelwal1662 2 года назад +83

    I dont care what anyone say about kunal the only thing i know is that kunal is one of the best teacher and a mentor for students like me who cant afford udemy ot another paid course

  • @VinodKumar-fn2iq
    @VinodKumar-fn2iq 3 года назад +51

    I wish this course was a lil bit fast paced.......I'm really in need 🥺

  • @ABHISHEKSHARMA-jj5jh
    @ABHISHEKSHARMA-jj5jh Год назад +66

    bro's recursion videos are even longer than the other youtubers full java course. Excellent.

  • @kaushalkawade3623
    @kaushalkawade3623 3 года назад +50

    Hey Bro you just changed my perspective about recursion, I am the one who resigned programming at the time of recursion.
    But your course gave me lots of confidence about recursion so thank you so much you are doing great work.

  • @kage-musha1702
    @kage-musha1702 3 года назад +78

    i was anxious if you ever abandoned this course , i geniunely got tears when i saw a new DSA video got uploaded thanks alot boss :D

    • @KunalKushwaha
      @KunalKushwaha  3 года назад +59

      I will complete it this month

    • @codingweb3904
      @codingweb3904 3 года назад +5

      @@abhishekc3556 i guess abdul bari sir, his teaching style is similar to abdul sir's teaching style.

    • @codingweb3904
      @codingweb3904 3 года назад +2

      @@abhishekc3556 yeah thats correct

    • @yashtalks7250
      @yashtalks7250 2 года назад +6

      @@KunalKushwaha Bro lakhs of students career is dependent on this course... A big thanks from all of us.....

    • @swastikpatro6436
      @swastikpatro6436 2 года назад +1

      @@KunalKushwaha It's been over a month, the course is good, please upload more videos..

  • @radhekrishnamishra5371
    @radhekrishnamishra5371 3 года назад +38

    Like you are saying you will upload all the remaining ds lectures within this month, I can guarantee you will have more 100+ subscribers from my college only .
    Also you will eventually cross the 100k subscribers marks definitely in this month only 🔥🔥🔥

    • @radhekrishnamishra5371
      @radhekrishnamishra5371 3 года назад +1

      Full support to you bro,bcuz of you I am attempting Java questions I owe you and I will make up it by adding 100 subscribers in your channel brother

    • @udaysingh2929
      @udaysingh2929 Год назад

      Not completed the course 🥲

    • @codeman0017
      @codeman0017 Год назад

      @@udaysingh2929 ongoing when ever he is free he will do just like uploading stacks and queues in last 2 months

  • @ankitjoshi2302
    @ankitjoshi2302 2 года назад +13

    hey kunal i have a very small code of reverse number recursion without any special function.
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int num=sc.nextInt();
    int reverse=reverseNumber(num,0);
    System.out.println(reverse);
    }
    public static int reverseNumber(int num,int sum) {
    if(num==0)
    return sum;
    sum=sum*10+num%10;
    return reverseNumber(num/10,sum);
    }

  • @DWEthiopia
    @DWEthiopia 2 года назад +19

    This is the best playlist for recursion in all of RUclips! Great job!

  • @vedified-spiritual7034
    @vedified-spiritual7034 2 года назад +13

    After watching the previous videos thoroughly, i did not face problem in any of the question of this one. You explain everything so well. You are a piro!😊

  • @hussaingagan9196
    @hussaingagan9196 2 года назад +12

    we can also solve the count zeroes question without taking an extra argument or helper function like the below way:
    static int count(int n){
    if (n == 0){
    return 0;
    }
    if (n%10 == 0){
    return 1 + count(n/10);
    }
    return count(n/10);
    }

    • @ihsannuruliman3656
      @ihsannuruliman3656 2 года назад +1

      with the helper the runtime and memory usage are usually better

  • @hudahabib-zq2oc
    @hudahabib-zq2oc 8 месяцев назад +12

    From Pakistan, I started this boot camp 1 week ago, and boom! I have improved my logical thinking more than I have learned in the past 11 months! The best lectures!! very dedicated and knowledgeable instructor. Excellent💯

    • @anshulprakash6564
      @anshulprakash6564 4 месяца назад +2

      Boom word was quite predictable

    • @itsdivanshugarg
      @itsdivanshugarg 4 месяца назад +1

      no offence but you could have just said that you didnt do shit in those 11 month lol😂
      even if you had studied 40-60 minutes a day for 11 months, there is no way in hell you can improve more than that in just 1 week

  • @zaidmujahid2884
    @zaidmujahid2884 3 года назад +6

    This course is best! But it's going a bit slow it would be great if you upload videos faster. Bcoz I have to study for my clg exams

  • @devanshdewan2597
    @devanshdewan2597 10 дней назад +1

    the organization of the questions is perfect . the questions have been tailored in such a way that it forces a student to learn deeply about recursion .

  • @Shubham-ek7jv
    @Shubham-ek7jv 3 года назад +11

    Million heart smiles come when ur videos come

  • @harshavardhangulla4058
    @harshavardhangulla4058 3 года назад +13

    Best content from the great mentor.. with a lot of patience.. ❤️

  • @anshgupta6754
    @anshgupta6754 2 года назад +7

    59:25
    alternate method (C++)
    int noOfZeros(int n){
    if(n==0){
    return 0;
    }
    if(n%10!=0){
    return noOfZeros(n/10);
    }
    return 1+noOfZeros(n/10);
    }

  • @onechance5664
    @onechance5664 Месяц назад +1

    ANOTHER METHOD TO COUNT ZEROS
    int countZero(int n){
    if(n==0)return 0;
    int count=0;
    if(n%10==0)count++;
    return count+countZero(n/10);
    }

  • @sbndBhanu546
    @sbndBhanu546 Месяц назад +1

    57:56 Palindrome using recursion without any other function
    static boolean palindrome2(int n){//without using any other helper function
    int len = (int)(Math.log10(n)) + 1;
    int tenPower = (int)(Math.pow(10,len-1));
    int firstNum = (n/tenPower)%10;
    int lastNum = n%10;
    if (firstNum != lastNum && len > 1){
    return false;
    }
    if(len == 1 || (firstNum == lastNum && len == 2)){
    return true;
    }
    n = n - firstNum*tenPower;
    return palindrome2(n/10);
    }

  • @adityaram7408
    @adityaram7408 8 месяцев назад +1

    53:51 by using another arguement :
    class reverseNum{
    private static int reverse(int n,int Ld){
    if(n==0) return Ld/10;
    return reverse( n/10 , 10*(n%10+Ld) );
    }
    public static int getReverse(int n){
    return reverse( n/10 , (n%10)*10 );
    }
    }

  • @DWEthiopia
    @DWEthiopia 2 года назад +1

    public class ReverseNumber {
    public int reverseDigits(int num) {
    return helper(num, "");
    }
    public int helper(int num, String reverse) {
    if (num == 0) return Integer.parseInt(reverse);
    reverse += String.valueOf(num % 10);
    return helper(num / 10, reverse);
    }
    }

  • @ronitpanda5964
    @ronitpanda5964 2 года назад +1

    JS solution without a helper and outside variable
    const reverseNumber = (n) => {
    if (n % 10 === n) {
    return n;
    }
    let digits = Math.floor(Math.log10(n)) + 1;
    return (
    (n % 10) * Math.pow(10, digits - 1) + reverseNumber(Math.floor(n / 10))
    );
    };

  • @trishalm1367
    @trishalm1367 2 года назад +4

    Amzing content!!..Keep up the great work..just wanted to know if you will be providing content on web development

  • @HarshYadav-w8x
    @HarshYadav-w8x 8 месяцев назад +1

    Hey brother kunal,
    for the reverse a number question I thought of a solution in which we calculate the power of 10 without using a helper function
    static int rev(int n) {
    if (n

  • @Sumit-lr1qj
    @Sumit-lr1qj 2 года назад +1

    *You should be given "BharatRatna"*

  • @Vanshkumar-co5pm
    @Vanshkumar-co5pm 2 месяца назад +1

    For Q-7 At 35:20, best way to do the question is:---
    static int reverseTheNo(int n) {
    if (n

  • @aswinbarath
    @aswinbarath 3 года назад +21

    The more we wait for future lectures, the better it gets 🥳

  • @vigneshwarapalanisamy2242
    @vigneshwarapalanisamy2242 2 года назад +1

    public static void main(String[] args) {
    int n = 1020000;
    System.out.println(numberOfZeros(n));
    }
    static int numberOfZeros(int n) {
    if (n%10 == n) {
    return n % 10 == 0 ? 1 : 0;
    }
    if (n%10 == 0)
    return 1 + numberOfZeros(n/10);
    else
    return numberOfZeros(n/10);
    }
    In this solution we don't need extra argument/ global variable. If this solution has any downside please comment.

  • @ALister_priyanshu
    @ALister_priyanshu 2 года назад +6

    such a great lecture ...man just love your teaching style❤️❤️....also bring the Dynamic Programming lectures soon.......

  • @muhammedkerim3625
    @muhammedkerim3625 2 года назад +1

    Count zeros will fail if n = 0 1:04:29
    The base condition can be:
    if(n%10 == n) return n == 0 ? ++count : count;

  • @hemangkothari7813
    @hemangkothari7813 Год назад +1

    Q7
    the easiest solution on Reverse Number
    static void reverse number(int n){
    if(n == 0){
    return;
    }
    System.out.print(n%10); // little tweak in the code take PRINT instead of println.
    reverseNumber(n/10);
    }

  • @TarunSai-i7b
    @TarunSai-i7b 6 месяцев назад +1

    1:05:00 If we give input number as zero it should return 1, not 0 because zero is also a number and no of zeroes in 0 is 1

  • @jaymistry689
    @jaymistry689 Год назад +1

    We can do question 7 without helper function like this,
    static int reverse(int n) {
    int base = (int)(Math.pow(10, (int)(Math.log10(n))));
    if (n%10 == n) {
    return n;
    }
    else {
    return ((n%10) * base) + reverse(n/10);
    }
    }

  • @achinttrivedi4667
    @achinttrivedi4667 2 года назад +1

    getting the last digit to the thousands place i was also trying by my own but it took so much you said there are many ways thinking which one to tell after that you just cut your video.... by this i got no one is pro it take time... hahaha but no offence 39:40

  • @SukeerthiLangu
    @SukeerthiLangu 2 месяца назад +1

    METHOD 3 FOR PEOLPLE LIKE ME
    public class Main {
    public static void main(String[] args) {
    System.out.println("Hello world!");
    System.out.println(fun(1243));
    }
    public static int fun (int n)
    {
    if(n%10==n)
    return n;
    System.out.print(n%10);
    return fun(n/10);
    }
    }
    thank me later😁

  • @yourdailydoseofmeemeee3006
    @yourdailydoseofmeemeee3006 Год назад +6

    Just finished the video and was able to do all the questions by myself just cause I revised the notes that I made in the recursion basics video.
    What a brilliant way to teaching man!
    Hats off to you!

  • @rajdip6324
    @rajdip6324 4 месяца назад +1

    This is what I came up with for the reverse of a number code(Q-07) :-
    public class Main
    {
    public static void reverse(int n){
    if(n==0){
    return;
    }
    System.out.print(n%10);
    reverse(n/10);
    }
    public static void main(String[] args) {
    System.out.println("The reverse of the number is : ");
    reverse(1234);
    }
    }

    • @abishekalwis3379
      @abishekalwis3379 3 месяца назад

      you are printing the number by number. if you change the print ---> println it would display line by line.

  • @Praneeethh
    @Praneeethh 8 месяцев назад +1

    woahhh !! Really great never thought recursion will be this easy.Kudos to you brotherr!

  • @Helly_Patel
    @Helly_Patel 2 года назад +12

    Thanks for teaching us like no one did till now!! One small request, please make lectures on dynamic programming as well!!

  • @alonbrim
    @alonbrim 2 года назад +4

    Another great video from Kunal!! Very clear, and thought step by step! Thank you very much!

  • @abhishekgupta3698
    @abhishekgupta3698 2 года назад +2

    Bro can u make tutorials on pointers concept pointers passed to function as an argument and also on dynamic memory allocation and Thanks for this

  • @UnyimeUdoh-ny3lp
    @UnyimeUdoh-ny3lp 9 месяцев назад +2

    Bro, the concept of an helper function is a game changer

  • @aryanarora5411
    @aryanarora5411 Год назад +1

    Kunal Bhaiya, I have just one thing to say, AWESOME !!!! PS : please can I get a heart from you :)

  • @piyushgupta6290
    @piyushgupta6290 3 года назад +3

    Maza aayaa....aur ye maza har programmer ko lena chahiye😆😆😍👍👍👍👍👍

  • @mightymiller2085
    @mightymiller2085 Год назад +1

    thank you so much Kunal Bhaiya..you are truely saviour...and hope for students like me of 3rd tier college

  • @harshtekwani8540
    @harshtekwani8540 2 года назад +1

    bro in q 7 you can simply print n%10 which is last no and call recursive fun(n/10)
    ie fun(n){
    if(n==0){ return; }
    sout(n%10) ; //ie last no
    fun(n/10);
    }

    • @kovidsingh3316
      @kovidsingh3316 2 года назад

      Wrong, just input 3410 and you'll see why.

  • @ayeshasolanki5386
    @ayeshasolanki5386 2 года назад +4

    Kunal, it's just just awesome, whenever you say it's the best course on DSA then you mean it, will recommend everyone to give it a try at least, and I promise you won't regret it later

  • @snehilsaxena6512
    @snehilsaxena6512 3 года назад +1

    last question ...counting steps.... @kunalKushwaha ....why did you not put other return statement in else.......for every "if" completion it will execute the next line right?..........i.e. return helper(num-1,steps+1) why it is not in else?

    • @ankitdwivedi4213
      @ankitdwivedi4213 3 года назад

      Bhai return statement inside if will get executed if condition is true and then the control will never come back to same function so the else can be ignored and we can place another return without else

  • @kovidsingh3316
    @kovidsingh3316 2 года назад +1

    Q7. Without helper function.
    public static int reverse(int a ) {
    int digits = (int)Math.log10(a) + 1;
    int tail = a % 10;
    if (a == 0) {
    return 0;
    }
    return tail*(int)Math.pow(10 , digits-1) + reverse(a/10);
    }

  • @NilavraPathak
    @NilavraPathak 2 года назад +7

    Nice lectures. I was able to do the reverse without an auxiliary function.
    def reverse(n : int) -> int:
    digits = (int)(math.log10(n))
    q, r = divmod(n, 10)
    if q == 0:
    return r
    return reverse(q) + r*10**(digits)

    • @sujaykumar2132
      @sujaykumar2132 2 года назад

      Hey man its real good but here's an another way !!!!
      static String rev(int n){
      if(n==0)
      return " ";
      return n %10 + rev(n/10);
      }
      As Kunal said, The arguments which we use will be passed to that recursion call and as I am using the return type as String so, we can get the same results;

  • @dipeshjadhav1546
    @dipeshjadhav1546 2 года назад +1

    Kunal be like why I am saying this again and again.. Well bro because that's RECURSION :D..you have seen Inception and now you experience Inception. :D .... Jokes apart hands down to the best Boot Camp ever. So much to learn day in day out. I just can't stop watching these videos. Thank you so much bro. I request you to open a patriotion page so we can contribute and give back to the community after we get better jobs.

  • @nikhilteja8171
    @nikhilteja8171 2 года назад +1

    Excellent lecture kunal bhaiyya!... This video helped me a lot... Thank you so much... appreciated...!

  • @nandikdevbhuti6070
    @nandikdevbhuti6070 2 года назад +1

    Came with this solution before seeing your solution. Is this an efficient approach?
    import java.util.Scanner;
    public class ReverseNumber {
    static int reverse(int n, int rev) {
    // base
    if (n == 0)
    return rev;
    int r = n % 10;
    rev = (rev * 10) + r;
    return reverse(n / 10, rev);
    }
    public static void main(String[] args) {
    System.out.print("Enter a number: ");
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    System.out.println("Reverse: " + reverse(n, 0));
    sc.close();
    }
    }

  • @shafaq-here
    @shafaq-here 2 года назад +4

    Kunal your teaching style is alot different from hundreds of high qualified professors out there . Just finished with the lecture , it was really amazing, learning how to approach these problems .
    Good vibes only 😌😌

  • @reyyisuresh8317
    @reyyisuresh8317 День назад

    I found it very helpful. The way you are explaining is so good. I was able to understand the suggestion "pen and paper" was working. Thanks for that.

  • @praveen_oficl
    @praveen_oficl Месяц назад

    We can eliminate the helper function also like below
    public static int reverseNum(int num) {
    if(num%10==num) {
    return num;
    }
    int digits = (int) Math.log10(num)+1;
    return (int) ((num%10)*Math.pow(10, digits-1)+reverseNum(num/10));
    }

  • @akshaykumar-wd8jc
    @akshaykumar-wd8jc 3 года назад +3

    Thanks for the amazing content Kunal even we can't find these kind of qualified videos in paid courses too please do more videos on the recursion topic this is really the most confusing topic for us

  • @ankitcoder6969
    @ankitcoder6969 2 года назад +1

    Reverse a num -
    Static int rev(int n) {
    If(n==0){
    return ;
    }
    int rem = n%10;
    System.out.print(rem);
    rev(n/10);
    }
    Simple 🤷🤷

  • @AdityaKeshari-p9t
    @AdityaKeshari-p9t 14 дней назад

    Kunal bro its a Excellent Course ...im litreally feeling very much fun while doing this recursion problems ....And because of your Guidance i am able to do it on my own ...ThankYou SO Much....

  • @madhugandamala8995
    @madhugandamala8995 21 день назад +1

    to see my comment please run this code
    class main
    {
    public static void main(String args[])
    {
    System.out.println("this DSA palylist is best playlist ever i seen")
    }
    }

  • @legend020goat
    @legend020goat 24 дня назад

    import java.util.*;
    public class Main
    {
    public static void main(String[] args) {
    System.out.print(countofzeroes(10004560));
    }
    static int c=0;
    public static int countofzeroes(int n)
    {
    if(n==0)
    {
    return c;
    }
    if(n%10==0)
    {
    c++;
    }
    return countofzeroes(n/10);
    }
    }
    is this correct way for count of zeroes?? Anyone??

  • @aryantyagi9372
    @aryantyagi9372 3 года назад +2

    Hey Kunal....with the advent of technologies such as AI/ ML and Data Science...Is it a possibility that they'll be replacing some of the development jobs ?
    Tx

  • @nishu0766
    @nishu0766 2 месяца назад +1

    Sir, please upload all the remaining topics of this playlist as your these videos are very informative and helpful in getting placed and there is no other such playlist available anywhere ,your playlist is a hundred times better than any other paid courses please upload remaining topics as soon as possible.

    • @thethreesowrdz
      @thethreesowrdz Месяц назад

      did you finish this bootcamp ? is this worth ? its my 2nd week in this bootcamp.

    • @nishu0766
      @nishu0766 Месяц назад +1

      @@thethreesowrdz No, i have not completed it yet . But yes, this DSA bootcamp is far better than many other free as well as paid courses .You will not regret for choosing this playlist. But this playlist is still incomplete 🥲and it doesn't seem that he is going to upload remaining topics of this playlist.

  • @AdityaX2703
    @AdityaX2703 Месяц назад

    to reverse a number without extra arguments
    public static int reverse(int n )
    {
    if(n==0){return 0;}
    int digits=String.valueOf(n).length();
    return ((int)((n%10)*Math.pow(10,digits-1))+reverse(n/10));
    }

  • @1saurabhkumar1
    @1saurabhkumar1 3 года назад +1

    Completed my first 100 questions on leetcode 🥺

  • @akash-
    @akash- 3 года назад +1

    #Solution_of_Reverse_a_Number_Using_Recursion
    int helper(int num, int rev=0){
    if (num==0){
    return rev;
    }
    rev = rev*10 + num%10;
    return helper(num/10, rev);
    }
    int reverseNum(int num){
    return helper(num);
    }

  • @rajarshichaudhuri
    @rajarshichaudhuri 7 месяцев назад +1

    Never thought that after purchasing paid courses from GFG and Coding Ninjas I will come here and clear out my doubts on recursion. I think the differentiating factor is also your crystal clear art of communication ....Thanks for making this video exist free for everyone.

  • @pozo-r1x
    @pozo-r1x 7 месяцев назад +1

    lecture is so crazzzy and dammm simpler in the whole world and he looks sooooooo cutee while teaching😁😁🙌🙌

  • @abhinjr4918
    @abhinjr4918 11 месяцев назад +1

    This man is fkkkkinnnnngggg legend.....
    I cant believe i solved in a row every problem without seeing his solution 😮

  • @amandeepbhatia
    @amandeepbhatia 2 года назад +1

    Great video - I could solve it in more easier way for countNumberOfZeros :
    static int countNumberOfZeros(int n){
    if (n==0) return 0;
    int mod = n%10;
    return (mod==0?1:0) + countNumberOfZeros(n/10);
    }

  • @kapilsingh2816
    @kapilsingh2816 3 года назад +1

    Is this channel better than pepcoding?
    Growing very faster than that

    • @KunalKushwaha
      @KunalKushwaha  3 года назад +1

      Watch the videos and decide for yourself

    • @kapilsingh2816
      @kapilsingh2816 3 года назад +1

      @@KunalKushwaha ya I watched , you are great Kunal
      But on pepcoding website , there is ide attached with questions that's very convenient and helpful ,if possible (sorry u r already doing too much for us) make your own website and attach ide along with questions , it will be beneficial for us as well as may help you to grow more

  • @raviraj-xq4ue
    @raviraj-xq4ue 2 года назад +1

    the last two question gave me GOOSEBUMPS🔥

  • @anishakumari6517
    @anishakumari6517 3 года назад +1

    Could anyone recommend channel for maths in btech cse?? 🙏🙏🙏

  • @anirudhbhat1442
    @anirudhbhat1442 Год назад +1

    It will not make any sense to debug the same thing again and again ....* Proceeds to debug....thats why we love his teaching

  • @abishekalwis3379
    @abishekalwis3379 3 месяца назад

    for the Q - 07 you can use this.
    public class ReverseNum {
    public static void main(String[] arg){
    int num = 123456789;
    int count = (int) ((Math.log10(num)) + 1);
    int reversedNum = reverseNumber(num, count);
    System.out.println(reversedNum);
    }
    private static int reverseNumber(int num,int count) {
    if(num/10 == 0){
    return num;
    }
    return (int) ((num % 10) * Math.pow(10, count - 1)) + reverseNumber(num/10, count - 1);
    }

    }

  • @SUBHADEEPDS
    @SUBHADEEPDS Месяц назад

    we can do the reverse a number in this way too
    "public class reversenum {
    public static void main(String[] args) {
    System.out.println(R(563417));
    }
    public static int R(int n){
    if(n%10==n){
    return n;
    }
    System.out.println(n%10);
    return R(n/10);
    }
    }"

  • @Parveensinghtomer9727
    @Parveensinghtomer9727 Год назад +1

    thanks for the video

  • @movierulz8566
    @movierulz8566 Год назад

    My reverse number code w/o helper fun
    public static int reverse(int x)
    {
    if(x%10 ==x)
    return x;
    int digit=(int)Math.log10(x);
    return (x%10)*(int)Math.pow(10,digit)+reverse(x/10);
    }

  • @gocrazy6177
    @gocrazy6177 2 месяца назад

    Solved every question without looking at any of the solution. I was able to do all the questions by myself solely 🥺. It took little long but i did on my own

  • @saravanasai2391
    @saravanasai2391 Год назад

    Javascript version
    const recursiveReverseNumber = (n, pow) => {
    if (n === 0) {
    return n;
    }
    return (n % 10) * Math.pow(10, pow) + recursiveReverseNumber(Math.floor(n / 10), pow - 1)
    }
    recursiveReverseNumber(n, String(n).length - 1)

  • @harshmore8869
    @harshmore8869 3 года назад +2

    1st here ,love to watch your content😊😊

  • @amanavengeraman
    @amanavengeraman 2 года назад

    *Reverse*
    public static int reverse(int n){
    if(n

  • @lalit-singh-bisht
    @lalit-singh-bisht Год назад

    My approach for solving countZeros:
    #include
    using namespace std;
    int countZeros(int n) {
    if(n==0) return 0;
    return ((n%10==0)?1:0)+countZeros(n/10);
    }
    int main() {
    int n; cin>>n;
    cout

  • @vigneshwarapalanisamy2242
    @vigneshwarapalanisamy2242 2 года назад +1

    class Solution {
    public int numberOfSteps(int num) {
    if (num == 0)
    return 0;
    if (num % 2 == 0)
    return 1 + numberOfSteps(num/2);
    return 1 + numberOfSteps(num - 1);
    }
    }
    100% fast with 86% efficient memory management :)...thanks kunal

  • @romeotangoo
    @romeotangoo 5 месяцев назад

    but log10(n) won't be calculating the correct number of digits if a number contains repeating values.
    For example, n = 141241
    log10(141241) = 2.14.. + 1 = 3
    Can someone clarify this!

  • @zafeerrangoonwala4741
    @zafeerrangoonwala4741 2 года назад +2

    It's a great video! I was quite skeptical about recursion but this video has boosted my confidence! Kudos to you!

  • @giteshpatidar9370
    @giteshpatidar9370 2 года назад

    For Que 7 (Reverse a number)
    static String fun(int n) {
    if(n==0) {
    return "";
    }
    int rem = n%10;
    n = n/10;
    return Integer.toString(rem) + fun(n);
    }
    public static void main(String[] args) {
    int ans = Integer.parseInt(fun(96));
    System.out.println(ans);
    }

  • @Manas-jy5qw
    @Manas-jy5qw 2 месяца назад

    Can we try to concise all code of reverse into one return value ie,
    static int R(int a){
    if(a

  • @satyasanatan22124
    @satyasanatan22124 2 года назад +1

    Way #3 for question 7
    and way simple
    static void printDigitsRev(int n){
    if (n/10==0){
    System.out.print(n%10);
    return;
    }
    System.out.print(n%10);
    System.out.println();
    n = n / 10;
    printDigitsRev(n);
    }
    love your teachings your proud student

  • @simranpreetkaur114
    @simranpreetkaur114 2 года назад

    _Ques 7_
    public static int reverseNum(int num)
    {
    int length=(int)(Math.log10(num));
    String stringMask=Integer.toBinaryString(1

  • @saidurgaprasad9913
    @saidurgaprasad9913 11 месяцев назад

    @KunalKushwaha here is my way of reversing a number by making use of first approach
    static int reverseNumber(int num) {
    return revNum(num, 0);
    }
    static int revNum(int num, int revNum) {
    if (num % 10 == num) {
    return revNum * 10 + num;
    }
    revNum = revNum * 10 + num % 10;
    return revNum(num / 10, revNum);
    }
    I just moved revNum variable to method arguments and made tweaks in base condition

  • @amansayer4943
    @amansayer4943 Год назад

    Question 10 without helper function .if its wrong please explain me helper function usage here.
    import java.util.*;
    public class Main
    {
    public static void main(String[] args) {
    System.out.println("COUNT THE NUMBER OF ZEROS");
    System.out.println(count(14,0));
    }
    public static int count(int num,int co){
    if(num == 0){
    return co;
    }
    if(num%2 == 0){
    return count(num / 2, co + 1);
    }
    else{
    return count(num - 1, co + 1);
    }
    }
    }

  • @AdityaX2703
    @AdityaX2703 Месяц назад

    Counting zeros without extra argument
    public static int count(int n)
    {
    if(n==0){return 0;}
    if(n%10==0)
    {
    return (1+count(n/10));
    }
    return (count(n/10));
    }

  • @vishalthakur2545
    @vishalthakur2545 Год назад

    Kunal Kushwaha's Thug Life.... 😎
    Starting : 39:15
    The Exact Moment: 39:30 😆

  • @codecorn8030
    @codecorn8030 3 года назад +2

    I think in taht prgm to find reverse of number
    If you using
    static int sum ;
    Then no need to keep it out of the function
    As static variables keeps values from previous function calls
    I guess so 😅

    • @akshaykumar-wd8jc
      @akshaykumar-wd8jc 2 года назад

      If you keep "sum" variable inside of the function don't you think for every function call the sum is also intialized to zero

    • @codecorn8030
      @codecorn8030 2 года назад

      @@akshaykumar-wd8jc Da if it was just
      int sum ;
      That would have happened
      But this is
      static int sum ;
      So every time function is called it won't get intialized to 0
      Just read once abt " static " qualifier for primtitive data types

  • @souvikmandal9706
    @souvikmandal9706 Год назад

    Hey @KunalKushwaha here's my solution for reversing a number:
    static int reverse(int n, int s) {
    if(n%10 == n) {
    return s+n;
    }
    return reverse(n/10, ((n%10 + s) * 10));
    }
    calling the method initially with n and 0.

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

    You beauty!! Never ever felt this confident after watching your recursion videos :)

  • @pavankumard5276
    @pavankumard5276 Год назад

    Another way to solve reverse of a number:
    if (n < 10) { return n; }
    return (n % 10) * (int)Math.pow(10, (int)Math.log10(n)) + reverseNumber(n / 10);

  • @rukaiyakhan2406
    @rukaiyakhan2406 2 года назад

    TO FIND THE REVERSE
    static int rev(int n){
    if(n==0)
    return 0;
    return n%10 * (int)(Math.pow(10, (int)(Math.log10(n)))) + rev(n/10);
    }
    without the helper function or taking variable
    please let me know if this can pass all the test cases.