The most simplified explanation one could ever get!
@HarshKumar-ip5nr Жыл бұрын
The edge case of overflow was amazing. Thank you for such amazing content. Consider completing the series we are eagerly waiting.
@mrsttechno5974 Жыл бұрын
Your teaching style is awesome, I understand everything in detail
@joeljacob4685 Жыл бұрын
Handling the overflow case was amazing !! I didn't got that one
@Bigg_boss_trolls9 күн бұрын
our teaching style is awesome
@bharatmehta30 Жыл бұрын
Was missing the overflow case. Thanks to this amazing video.
@harshmagarwal31966 ай бұрын
Sometimes I feel he is scolding me. But honestly this is one of the best playlist available on YT.
@VarshaSingh-hi2sb3 ай бұрын
What will be the time complexity ? will it be nlogm where m is the number whose root needs to be calculated and it the given power? log m for BS and multiply it with n foe calculate power of every number am I right ?
@mahidhruv72 ай бұрын
@@VarshaSingh-hi2sb Yes correct, complexity will be O(n log (m))
@rishabhgupta12222 ай бұрын
@@VarshaSingh-hi2sb it feels lyk u are scolding 😅
@KrishnaKumar-b4m9p3 күн бұрын
@@VarshaSingh-hi2sb for calculating power there are 2 approaches with time complexity O(n) and O ( log n). so your overall time complexity will depend on which method u choose. where as for the binary search part time complexity will be O (log m)
@dank7044 Жыл бұрын
suppose M=10^63-1;( max value of long long), and mid=10^63/2, now is mid
@girikgarg8 Жыл бұрын
Done, Here's my approach to this question: long long binPower(int a,int b,int m){ long long ans=1; long long temp=a; while (b){ if (temp>m || ans*temp>m) return INT_MAX; // so that high moves to mid-1 if (b&1){ ans=1LL*ans*temp; } temp=1LL*temp*temp; b>>=1; } return ans; } int NthRoot(int n, int m) { int low=1; int high=m; int ans=0; while (lowm) high=mid-1; else low=mid+1; } return -1; }
@cinime Жыл бұрын
Understood! Super amazing explanation as always, thank you so so much for your effort!!
@suryanshsoni3420 Жыл бұрын
long start = 1; long end = m; while (start m / (Math.pow(mid, n - 1))) { end = mid - 1; } else if (mid < m / (Math.pow(mid, n - 1))) { start = mid + 1; } else { return (int) mid; } } return -1; This also works.
@yashaggarwal60139 ай бұрын
what is the logic behind m / (Math.pow(mid, n - 1) ?
@suryanshsoni34209 ай бұрын
@@yashaggarwal6013 mid * mid**(n-1) = mid**n
@omkarsawant92679 ай бұрын
Edge case explained when mid^n > m then overfllow occurs int func(int mid, int n, int m) { long long ans = 1; for (int i = 1; i m) { return 2; } } if (ans == m) { return 1; } // return 1 if ans == m return 0; // return 0 if ans < m } For example, let's say mid = 3, n = 2, and m = 8. During the loop, the value of ans will be calculated as follows: ans = 1 * 3 = 3 (after the first iteration) ans = 3 * 3 = 9 (after the second iteration) At this point, ans (which is now 9) is greater than m (which is 8), and the function will return 2, indicating that 3^2 is greater than 8.
@AtulKumar-c4x7l Жыл бұрын
understood Thank you striver for such an amazing explanation.
@KeepCoding692 ай бұрын
It's better to keep high as m/n. We can reduce the number of checks using this.
@AayushRana-kl4lj Жыл бұрын
Root of any even num is always even and same goes with odd too. We should apply this concept too to reduce a bit of time complicity.
@manavsingh5919 Жыл бұрын
Thank you Striver....Understood everything🙂
@hareshnayak73028 ай бұрын
Understood,Thanks striver for this amazing video.
@johndurai2226 Жыл бұрын
I am your big fan because of your videos are well and explanation also
@NitinKumar-wm2dg Жыл бұрын
understood bhaiya, thank you for this tutorial
@venkateshcharyakaram65472 ай бұрын
explaining the concepts excellent
@AnmolGupta-oj4lm Жыл бұрын
Understood Very Well!
@priyanshuchoudhary246 Жыл бұрын
Amazing Playlists
@kunalsingh8796 Жыл бұрын
consistency to gave such awesome videos makes u a good youtuber ...keep doing sir
@DivyamGupta-ly4ds Жыл бұрын
oh i really see that coming....😂😂
@purushottam1085 ай бұрын
to understand this video i lean power exp it take me 2 hrs to learn because of -ve power in leet code ,and at last striver solve this porblem by simple for loop.🤩🤩🤩🤩🤩🤩❤❤😥😥
@KrishnaKumar-b4m9p3 күн бұрын
dont worry that will also be useful. it was asked in meta coding interview to implement pow(x,n) function using log n time complexity
@shoaibaltaf11282 ай бұрын
int NthRoot(int n, int m) { int low=1; int high=m; int mid; while(lowm)high=mid-1; else low=mid+1; } return -1; } this code got submitted at once without any overflow
@srilathareddy94507 ай бұрын
wow explanation
@karthik-varma-15793 ай бұрын
public class Solution { public static int NthRoot(int n, int m) { int ans = -1; int low = 1; int high = m; while(low m){ high = mid - 1; } else{ low = mid + 1; } } return ans; } }
@HardikDoshi-ml8ii5 ай бұрын
can we use power func --- pow(mid,n) ??? instead of writing different function??
@THIRUORUVAMMEY5 күн бұрын
int ans = 0; for(int i=1;i
@captainakash89146 ай бұрын
thanks you striver for.... easy explanation
@oyeesharme3 ай бұрын
understood bhaiya
@graviton0014 ай бұрын
Solved this too myself thnx ❤
@ashutoshranjan4644 Жыл бұрын
In python, it doesn't cause any issue with that code. But thanks for that edge case of c++.
@KarthikNandam-xs4qnАй бұрын
understood my g 🔥
@harshilpatel32053 ай бұрын
Understood 🙏🏻
@codeman38283 ай бұрын
Understood.
@justcodeitbro1312 Жыл бұрын
Damn bhai what a great explanation thanks alot
@TrinmoyDutta8 ай бұрын
lets assume we need to find nth root of num, so if we set low=0, high=num/n, then the overflowing edge case can be avoided to some extent, as we know nth root cannot exceed num/n...
@DeadPoolx17123 ай бұрын
UNDERSTOOD;
@music-loverFam3 ай бұрын
Understood😊
@VivekSharma-sk3vp7 ай бұрын
understood!! nicely
@diponchetia93816 ай бұрын
understood clearly
@nowornever85522 ай бұрын
Understoood
@NazeerBashaShaik7 ай бұрын
Understood, thank you.
@Learnprogramming-q7f9 ай бұрын
Thank you Bhaiya
@chiragbansod82528 ай бұрын
UNDERSTOOD
@YourCodeVerse11 ай бұрын
Understood✅🔥🔥
@senseiAree Жыл бұрын
Understood ❤
@sarangkumarsingh79016 ай бұрын
Understood...............
@savitore7 ай бұрын
when you are modifying code for overflow, the T.C got changed to O(n*logm). How to do it in O(logn logm)?
@mcbotface Жыл бұрын
Can you share the code where you modify exponentiation function to handle overflow situation instead of naive multiplication function?
@SYCOA12CHAITANYAASOLE5 ай бұрын
Understood !! 😎😎
@harsh_parmar6019 ай бұрын
Understood 🎉
@lakshmiprasanna7058 Жыл бұрын
Understood 💯💯💯
@meenakshitewary7015Ай бұрын
God explantion
@yashaggarwal60139 ай бұрын
Why can't we use pow(mid,n) to calculate power instead of writing an entire function in C++?
@RAHULMAHESHWARIdexter6 ай бұрын
watch the video from 15:30 till end, it will cause overflow. one workaround is to do pow(mid,1/n), take floor of it and check if it is same as the number (i mean to say if its a integer instead of some float value like 3.21 something)
@modiji8706 Жыл бұрын
able to write this code myself
@shaiksoofi37418 ай бұрын
understood Thank you
@padmavatishah99228 ай бұрын
Understood sir
@dreamyme543 Жыл бұрын
understood🙃
@shubhamkumar170 Жыл бұрын
Understood!
@rushithagudipudi77427 ай бұрын
Understand
@AbhishekBhattacharjee-j2m Жыл бұрын
UNDERSTOOD
@thatsathishkumar Жыл бұрын
Nice bhai
@CodewithKing3603 ай бұрын
bhaiyya in square root question we can minimize some iteration using high=n/2 a squreRoot of number always lies in 1 to num/2😄
@afrazurrahmantial68053 ай бұрын
Not some, only 1 iteration
@AmanKumar-qz4jz Жыл бұрын
thanks
@ayushirastogi9725 Жыл бұрын
yep understood!!
@drizzle01 Жыл бұрын
understood
@ShubhanshuG007 Жыл бұрын
Understood
@AtulKumar-c4x7l Жыл бұрын
Striver can u please explain how can I do with binary exponentiation.....i tried still i am not able to figure it out.... i used following code: long long ans=1; while(n>0) { if(n%2==1) { ans=ans*mid n=n-1; } else{ mid=mid*mid; if(mid>m) return 2; n=n/2; } } if(ans==m) return 1; return 0;
@rishabhagarwal6057 Жыл бұрын
This is using binary exponentiation. TC = O(log(m)*log(n) class Solution{ public: long long fun(long x, long long n, long long m){ long long ans =1; while(n>0){ if(n%2==1){ ans=ans*x; if(ans>m) return -1; n--; } else{ x=x*x; if(x>m) return -1; n/=2; } } } int NthRoot(int n, int m) { long long low =0; long long high =m; while(low
@MohitKumar-o3l1u6 ай бұрын
Understood!!
@humanity7880 Жыл бұрын
understood!
@rupalikumari88294 ай бұрын
Understood:)
@amitranjeetjha1240 Жыл бұрын
Understood
@shaswatshah49205 ай бұрын
Can't we use mid**n to check and then increase or decrease the low and high accordingly. this way we don't have to use the function and no need of for loop also
@gopimalisetti7900 Жыл бұрын
Understood! 😀
@utsavseth6573 Жыл бұрын
Lovely.
@random_akki Жыл бұрын
instead of func can we use pow(mid,n)??
@Sankhamit Жыл бұрын
no at the end of the video bhaiya explained the case of 10 to the power 90 which will overflow so we use the function , if we use pow it will directly give 10 the power 90 which will overflow and we ll not get output
@random_akki Жыл бұрын
@@Sankhamit leetcode accepted the solution using pow
@Raj10185 Жыл бұрын
my implementation :- typedef long long ll; ll multiply(ll mid , int n,int m) { ll ans=1; for(int i=1;im) { //to overcome the overflow bada ho gya to bas break kar do break; } } return ans; } int NthRoot(int n, int m) { if(n==1) return m; int low = 1; int high = 1e5; while(low
@ArpanChakraborty-do6yz9 ай бұрын
just op❤🔥💯
@raghavkansal3765 Жыл бұрын
"understood"
@sahadevnai80404 ай бұрын
public class Solution { public static int NthRoot(int n, int m) { int low = 1; int high = m; while (low m) break; } if (val == m) { return mid; } else if (val > m) { high = mid - 1; } else { low = mid + 1; } } return -1; } }
@shashwat_harsh Жыл бұрын
understood.
@RaunitJaiswal-s9v2 ай бұрын
Last for today 😮
@akashkumaryadav18273 ай бұрын
🔥
@DevanshiKapla Жыл бұрын
instead of the check func can we use inbuilt power func that will also work
@takeUforward Жыл бұрын
Overflow case will be an issue
@DevanshiKapla Жыл бұрын
@@takeUforward Okay bhaiya
@kushagramishra5638 Жыл бұрын
UnderStood!
@suryasaimaheswar86364 ай бұрын
understood:)
@esmamanyt7048 Жыл бұрын
i have a doubt this just failing the test case but not giving any error and if it not giving an error how can we suppose to find out the problem there has to be any trick or tips for this type of edge case
@prthms_9 ай бұрын
i got it
@MischievousSoul Жыл бұрын
Cfbr
@googleit2490 Жыл бұрын
Understood :)
@dayashankarlakhotia4943 Жыл бұрын
Understood please solve some hard problems
@mangeshtale28182 ай бұрын
int NthRoot(int n, int m) { // Code here. int low=1; int high =m; while(low m){ high = mid-1; }else{ low = mid+1; } } return -1; } T.C = O(logm * logn) logm (for binary search) and logn(for calculations of power) so isn't this better??
@Manishgupta200 Жыл бұрын
Dealing with the overflow case is too tricky. That's kind of thing is taughts you only
@akshatsamdani Жыл бұрын
Isnt the time complexity for this code is O(nlogm)
@suyashmishra6946 Жыл бұрын
Understood!
@raghavkansal3765 Жыл бұрын
what is return 1 return 0 and return 2 i didnt get that