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 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!
@@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.
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
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.
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 🔥🔥🔥
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); }
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!😊
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); }
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💯
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
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 .
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); }
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
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.
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); }
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); } }
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
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😁
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!
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); } }
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); }
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
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?
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
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); }
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)
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;
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.
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(); } }
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 😌😌
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)); }
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
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....
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") } }
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??
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
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 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.
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)); }
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.
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); }
@@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
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); }
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); } }"
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); }
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
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
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!
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); }
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
@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
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); } } }
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 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
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.
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.
DSA + interview preparation playlist: ruclips.net/p/PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ
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!*
You're very welcome!
@@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!
@@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) ;
@@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.
@@Rajdweep Recursive problems can be solved in different ways, there is no single way to solve it. What's important is understanding the concept !!!🙌
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
I wish this course was a lil bit fast paced.......I'm really in need 🥺
@@suhaspatnaik Bro
Link?
Will be completed this month
@@KunalKushwaha Thx bro for your hard work
bro's recursion videos are even longer than the other youtubers full java course. Excellent.
true
check durga software solutions for java
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.
The same happened to me as well
Thanks Kunal!
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
I will complete it this month
@@abhishekc3556 i guess abdul bari sir, his teaching style is similar to abdul sir's teaching style.
@@abhishekc3556 yeah thats correct
@@KunalKushwaha Bro lakhs of students career is dependent on this course... A big thanks from all of us.....
@@KunalKushwaha It's been over a month, the course is good, please upload more videos..
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 🔥🔥🔥
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
Not completed the course 🥲
@@udaysingh2929 ongoing when ever he is free he will do just like uploading stacks and queues in last 2 months
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);
}
This is the best playlist for recursion in all of RUclips! Great job!
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!😊
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);
}
with the helper the runtime and memory usage are usually better
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💯
Boom word was quite predictable
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
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
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 .
Million heart smiles come when ur videos come
Best content from the great mentor.. with a lot of patience.. ❤️
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);
}
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);
}
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);
}
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 );
}
}
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);
}
}
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))
);
};
Amzing content!!..Keep up the great work..just wanted to know if you will be providing content on web development
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
*You should be given "BharatRatna"*
For Q-7 At 35:20, best way to do the question is:---
static int reverseTheNo(int n) {
if (n
The more we wait for future lectures, the better it gets 🥳
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.
such a great lecture ...man just love your teaching style❤️❤️....also bring the Dynamic Programming lectures soon.......
Count zeros will fail if n = 0 1:04:29
The base condition can be:
if(n%10 == n) return n == 0 ? ++count : count;
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);
}
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
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);
}
}
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
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😁
🤣you got me
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!
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);
}
}
you are printing the number by number. if you change the print ---> println it would display line by line.
woahhh !! Really great never thought recursion will be this easy.Kudos to you brotherr!
Thanks for teaching us like no one did till now!! One small request, please make lectures on dynamic programming as well!!
Another great video from Kunal!! Very clear, and thought step by step! Thank you very much!
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
Already done
Bro, the concept of an helper function is a game changer
Kunal Bhaiya, I have just one thing to say, AWESOME !!!! PS : please can I get a heart from you :)
keep going bro
Maza aayaa....aur ye maza har programmer ko lena chahiye😆😆😍👍👍👍👍👍
thank you so much Kunal Bhaiya..you are truely saviour...and hope for students like me of 3rd tier college
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);
}
Wrong, just input 3410 and you'll see why.
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
Thank You
you are intern at google?
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?
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
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);
}
thank you! this works!.
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)
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;
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.
Excellent lecture kunal bhaiyya!... This video helped me a lot... Thank you so much... appreciated...!
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();
}
}
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 😌😌
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.
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));
}
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
Reverse a num -
Static int rev(int n) {
If(n==0){
return ;
}
int rem = n%10;
System.out.print(rem);
rev(n/10);
}
Simple 🤷🤷
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....
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")
}
}
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??
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
no
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.
did you finish this bootcamp ? is this worth ? its my 2nd week in this bootcamp.
@@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.
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));
}
Completed my first 100 questions on leetcode 🥺
#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);
}
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.
lecture is so crazzzy and dammm simpler in the whole world and he looks sooooooo cutee while teaching😁😁🙌🙌
This man is fkkkkinnnnngggg legend.....
I cant believe i solved in a row every problem without seeing his solution 😮
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);
}
Is this channel better than pepcoding?
Growing very faster than that
Watch the videos and decide for yourself
@@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
the last two question gave me GOOSEBUMPS🔥
Could anyone recommend channel for maths in btech cse?? 🙏🙏🙏
It will not make any sense to debug the same thing again and again ....* Proceeds to debug....thats why we love his teaching
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);
}
}
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);
}
}"
thanks for the video
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);
}
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
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)
1st here ,love to watch your content😊😊
*Reverse*
public static int reverse(int n){
if(n
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
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
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!
It's a great video! I was quite skeptical about recursion but this video has boosted my confidence! Kudos to you!
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);
}
Can we try to concise all code of reverse into one return value ie,
static int R(int a){
if(a
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
_Ques 7_
public static int reverseNum(int num)
{
int length=(int)(Math.log10(num));
String stringMask=Integer.toBinaryString(1
@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
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);
}
}
}
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));
}
Kunal Kushwaha's Thug Life.... 😎
Starting : 39:15
The Exact Moment: 39:30 😆
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 😅
If you keep "sum" variable inside of the function don't you think for every function call the sum is also intialized to zero
@@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
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.
You beauty!! Never ever felt this confident after watching your recursion videos :)
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);
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.