Instead of multiplying by running a for loop, we can use Binary Exponentiation technique to do in log N. Video: kzbin.info/www/bejne/omG8dGZubJukrsk
@secondguy3 жыл бұрын
so sir, should the time complexity be logN*log(M*10^d)??
@pranavgawade15463 жыл бұрын
You shoud not sacrifise your sleep for this.
@Usurperhk3 жыл бұрын
Can't believe you work late nights to deliver quality content in community. That's what makes you different and an inspiration to many students.
@Ben10qz3 жыл бұрын
Fun fact : Scalar is showing their add here also in between the video !
@Mr_SSK2 жыл бұрын
We can reduce the search space by taking 'high=m/2' initially. But, here we need to handle the case of n==1 explicitly, that means when n==1 ( we want the 1st root of m) we have to directly return m. We won't go for any calculations. -> We can set high=sqrt(m) as well, but in that case you have to make sure the sqrt() returns double (instead of int) Anyways, AMAZING EXPLANATION! 💜🙏
@vanshikagarg4893 жыл бұрын
Overall complexity is N Log(N) by doing... We can also count the the number of element which are smaller than mid in O(n + n ) . Instead of doing binary search on every row we can compare last element of every row if it it smaller than mid we take count of row size or if it is greater we can traverse the row by back until elem is bigger than mid. This takes O( n + n ) time.
@vanshsehgal94752 жыл бұрын
what do you mean by row?
@lifegood64013 жыл бұрын
1 clock waali baat ne emotional kr diya. Great Explanation. Mja aa jata hai aapki videos dekh kr. I am confident i am going to do good in placements if i finish this series honestly
@sanbidrc3 жыл бұрын
We can never thank you enough for such amazing content.
@OatsAurCode Жыл бұрын
DP series is helpul. Somehow the code not passing all the test cases in gfg. So adding a working code. That might be helpful class Solution: def NthRoot(self, n, m): # Code here if m == 1: return 1 if n==0: return 1 if n==1: return m start = 0 end = m//2 while start
@bhaveshkumar68423 жыл бұрын
There's nobody like you, Striver. You're the BEST!!!!
@govindsharma76963 жыл бұрын
Bhaiya aap jadugar ho , kya samjhate ho mashallah ❤️❤️
@AbidAhsan-yp4dc3 жыл бұрын
this is the best explanation of the problem you can find on entire internet . thanks a lot
@jayachandra6773 жыл бұрын
I thought this would be just like mid*mid == n but I didn't know that decimal thing. Also I blindly thought that the time complexity will be O(n*log(n)). Thanks for the video bhaiya!!!
@amarks4442 жыл бұрын
i am watching this video at 2:04am 🥱 , and when i heared "recording video at 1:00 am and sleep at 4:00 am after editing" , my energy get boosted 😎🤩 ....
@senpaidawwwggg Жыл бұрын
2:51 LoL
@arnabghosh96322 жыл бұрын
We can use binary exponentiation or can use inbuilt pow function to calculate the power this will reduce the TC to O(LogN * log(M*decimal*10)
@akankshamaurya92192 жыл бұрын
But using inbuilt pow function ,it is not passing all test cases
@immortal4412 Жыл бұрын
@@akankshamaurya9219 it is working check in gfg practice
@pratyushbhatt17123 жыл бұрын
Great!! You can further optimize the solution to a much greater extent bdw. When using the multiply function, you are using a very naive technique to calculate the Power, instead we can use Binary Exponentiation, which is logarithmic in nature. That will fasten it up. Great explanation bdw.
@takeUforward3 жыл бұрын
Yeah I have mentioned in the pinned comment :)
@pratyushbhatt17123 жыл бұрын
@@takeUforward yeah just saw that.. Anyways, great content as always.
@aandz61943 жыл бұрын
@@takeUforward Im little confused because..... Either we get the root of the number don't we check until 10^(-6)....... So what will be time complexity now in the worst case.....?
@sonuGupta-vo8vm2 жыл бұрын
Always learn new concept . And you makes CP more interesting . I likes your way of explaining time and space complexity. Thanks
@kartikgarg93793 жыл бұрын
Bhaiya your graph series is amazing and those dry runs are awesome thanks bhaiya
@RamKumar-kz8gg3 жыл бұрын
enjoy
@411_danishranjan92 жыл бұрын
why you take low = mid, why not low= mid+1 and high = mid, why not high = mid-1
@deepraj26312 жыл бұрын
As you can see that he took 1 base indexing not zero base indexing, hope you can get the idea why it's happening so
@harshabellamkondasrinivasa45273 жыл бұрын
omg.....4'o clock in the morning.... hats off to ur dedication sir. Can't thank u enough
@parthparmar97982 жыл бұрын
this is what I want. an amazing playlist for Binary search.
@jothamprince87652 жыл бұрын
thanks man, u just saved me from failing my class assignment, i've been trying to crack that for 3 days
@krishnakumar-rp9wc3 жыл бұрын
can we use pow instead of multiply function?
@kaichang8186Ай бұрын
understood, thanks for the great explanation
@ReD4eva943 жыл бұрын
I have seen a lot on youtube. You are the very best.
@harleenkaur7751 Жыл бұрын
Thanks a lot striver. We always learn a new concept through your lecture.
@prithvichetty153 жыл бұрын
Best Explanation of Binary Search. Eagerly Waiting for your Tree Series!!!❤❤
@yeswanthh50682 жыл бұрын
Thank you sir understood
@harshitvarshney26273 жыл бұрын
Great Explanation bhaiya Bhaiya....please make a playlist on the tree as well.
@cpwithsundar3 жыл бұрын
There is no match for your hardwork , but we too would work hard even if it doesn't surpasses yours.
@dayanandraut56603 жыл бұрын
Great explanation around intuition building and time complexity. Keep it up bro
@manavmalhotra85132 жыл бұрын
public class Solution { public static double findNthRootOfM(int n, long m) { // Write your code here. double lo=1; double hi=m; double eps=1e-7; while((hi-lo) > eps){ double mid = (lo+hi)/2.0; if(multiply(mid,n)
@dipanshusharma90842 жыл бұрын
make these changes cout
@muhsinmansooriee_0017 Жыл бұрын
@@dipanshusharma9084 why did we do this? as it is asking in the question to check for up to 6 decimal points.
@dipanshusharma9084 Жыл бұрын
@@muhsinmansooriee_0017 because in the ans it was taking upto 9 decimals , there was mistake in test cases
@prakharanand7778 Жыл бұрын
because when you are passing the argument to the multiply method, you are storing mid in parameter n and n in parameter m method call. But you are running the for loop inside multiply() n times which actually is mid due to your incorrect argument order during method call. fix it and your code will work just fine.
@gather.in.coding.lounge2 жыл бұрын
You are just doing all the way great, I really thank you for all these wonderful playlists.
@prakharanand7778 Жыл бұрын
In time complexity from 1 to say 27 there aren't 10*27 real numbers for upto 1 decimal place. 1.0 1.1 1.2 .... 1.9 (10 nos) 2.0 2.1 ... 2.9 (10 nos) ... 26.0 26.1...26.9 (10 nos) total nos till now = 10*26. And one more number 27.0 which makes the total real numbers from 1 to 27 equal to 10*26 + 1 => (M-1)*10 + 1? If no please explain.
@parthkabra88803 жыл бұрын
no words, excellent explanation
@RohitKumar-dy2gc Жыл бұрын
u r so dedicated man i wanna be also that much
@AkshayKumar-kp2ye2 жыл бұрын
My thought process went towards the mathematics approach initially. Wasn't able to deduce the binary search approach on this. Thanks for the video bro. double findNthRootOfM(int n, int m) { // Write your code here. return exp(log(m)/n); }
@antiquefood62843 жыл бұрын
Recently asked in Apple Interview to my experienced brother !!!
hey striver could you make a video for a non engineering background student to start coding journey and get into top companies road map sort of thing
@RamKumar-kz8gg3 жыл бұрын
watch love babber video
@ShwetaSingh-qw7mo2 жыл бұрын
great explanation
@amitzerikunthe7635 Жыл бұрын
hats off to ur dedication 🙏
@Ballistic_Bytes Жыл бұрын
A much simpler method of solving it would be to just use log and antilog. Following is a TypeScript Solution:- const nthRootOfM = ( n: number, m: number, ): number => Math.exp(Math.log(m) / n);
@harshitsaxena7205 Жыл бұрын
do you have any question on std platform please provide me for practise
@jayadubey_223 жыл бұрын
keep educating bhaiya nicely explained
@sourabhchoudhary72893 жыл бұрын
why can't we put an extra condition for multiply(mid,n)==m then return mid?
@SudhanshuKumar-lp1nr3 жыл бұрын
Because it will take a lot more iteration to become equal to root(M).
@srijitmondal41903 жыл бұрын
@@SudhanshuKumar-lp1nr why? We are not putting the condition inside while loop instead we are putting this as an extra if()
@sauravkumargupta25943 жыл бұрын
Ye jo unlike krne wale hai na... Unka mental level hi nhi itni asan videos ko smjhne ka 😂😂
@s.g.prajapati35972 жыл бұрын
Great content bhaiya! Learned and understood to the fullest!
@willturner34403 жыл бұрын
Sde sheet become interesting day by day
@aaaa-pr2dd3 жыл бұрын
😳awesome dada, didn't knew to use binary search this way
@saurabh44gupta3 жыл бұрын
Hi, I want to know why we need to apply Dijkstra to find the shortest path when we find the shortest path using BFS traversal.
@RamKumar-kz8gg3 жыл бұрын
following
@striver_793 жыл бұрын
BFS will take longer since it does not follows the greedy method of choosing the shorter path, so you will end up pushing any node a number of times into the queue actually.. which will end up taking a lot of time, over here, you always start with the shortest node reachable and then try to move ahead..
@darkamv-x58222 жыл бұрын
You are best
@pawanlok17762 жыл бұрын
thank you for making this video ,
@techcode356 Жыл бұрын
Thank You!
@bhaveshkumar68423 жыл бұрын
Thank you, Striver!!!!!!!!!!
@sarthaksinghrajput54623 жыл бұрын
Thank you Bhaiya!
@nileshsinha78693 жыл бұрын
Great explanation (as always)👌🙌
@mayankkumar48643 жыл бұрын
bhaiya, can you please explain that, why didn't you return the value of "low" or "high" from the function double getNthRoot , as it will be the value of the root ?
@CodePinaka2 жыл бұрын
understood
@ayushbisht26893 жыл бұрын
Best explanation.
@funenjoynilaypatel45532 жыл бұрын
9 march 2022 9:39 pm
@aandz61943 жыл бұрын
Im little confused because..... Either we get the root of the number don't we check until 10^(-6)....... So what will be time complexity now in the worst case.....?
@lakshmiprasanna7058 Жыл бұрын
Understood 💯💯💯
@jotaroackerman34473 жыл бұрын
amazing video bhaiya
@s_3095 Жыл бұрын
thanks bhai striver
@shubhambhardwaj88943 жыл бұрын
Thanks
@shubhamnalawade16063 жыл бұрын
Outstanding explanation
@shubhamnalawade16063 жыл бұрын
Could you please make videos solving coding problems in contests
@son_of_a_dentist8107 Жыл бұрын
very good video
@antrapurohit80102 жыл бұрын
great solution. but it is not accepted in coding ninja platform
@AbhishekKumar-td5zu3 жыл бұрын
tqsm bhaiya
@radharamamohanakunnattur3035 Жыл бұрын
Understtood!! and a Big Thanks!!
@dhruvmittal49923 жыл бұрын
why the search space is not 1 to 13 in first example ?
@abcsumits2 жыл бұрын
what about interpolation search?
@yashwagh833 жыл бұрын
Thanks for your efforts and sleepless nights. You are doing god's work Raj.
@ankitkholiya43052 жыл бұрын
Thanks bro you are great
@srujanat4832 жыл бұрын
Understood
@tejaswi46503 жыл бұрын
How did you decide we need to stop at 1e - 6?
@prakharagarwal62373 жыл бұрын
it will be given in the question itself
@shivansh80062 жыл бұрын
Why we can not use this " return pow(2, log2(m) / n); ". It will give the same answer :/
@shivansh80062 жыл бұрын
Bhai ye btado yar koi, iski time complexity kam hai na compare to the solution given in the video??
@sonushaw37152 жыл бұрын
Thank you bhaia love you❤
@prateekverma91663 жыл бұрын
Can anybody tell why we haven`t used low=mid+1 or high=mid-1
@takeUforward3 жыл бұрын
Because we want annswer in terms of decimal places, doing a -1 will not help :)
@prateekverma91663 жыл бұрын
@@takeUforward Got it ,thanks Striver
@Sksahu_1233 жыл бұрын
Bhaiya jisme setprecision use karte so wale bhi question upload kardo
@kushalchakraborty8615 Жыл бұрын
Great content
@umarqureshi84993 жыл бұрын
so good bhai!!!!!!!!!
@ahishnar15683 жыл бұрын
Really nice explanation striver.
@takeUforward3 жыл бұрын
Pura th dekh lo 😂
@ishankbansal92393 жыл бұрын
@@takeUforward 🤣🤣🤣🤣🤣🤣🤣🤣
@ahishnar15683 жыл бұрын
@@takeUforward Pehle se pata hai sir Awesome hi hone wali hai. I am your current batch student. That is why I know. 😅☺️🤘
@Steve-kv5we Жыл бұрын
Understood💯💯
@thrilokponnuru31312 жыл бұрын
Why the search space start from 1? What happens when m value is negative
@shubhamrana17762 жыл бұрын
Sir in the constraints N=300 and since we are searching in 1 to m , Why the value x ^300 not overflowing while calculating the power? Please help
@amitkumaryadav72402 жыл бұрын
Can anyone explain why time complexity is not n×log(m)
@AnkitMishra-mz4xt3 жыл бұрын
Eagerly wanting
@codeguy213 жыл бұрын
@striver , please use this channel also to i.e in english about how u do in your hindi channel ! that would be great for non hindi speakers ! thanks
@shubhamsinha2362 Жыл бұрын
Why can't we just use the Pow function?
@ayushkapri90823 жыл бұрын
why search space is not reduced to mid - 1, why just mid ??
@takeUforward3 жыл бұрын
Because mid could be your answer..
@SatyamKumar-bw4vi2 жыл бұрын
Hare Krishna !🙂
@bilalkhan22982 жыл бұрын
Can't thank u enough
@Tommyshelby602 Жыл бұрын
low = 0 to pass 11th tc on coding ninja
@ng3w4623 жыл бұрын
Can I achieve command on full DSA in 6 months?
@RamKumar-kz8gg3 жыл бұрын
you can do whatever you can imagine
@ng3w4623 жыл бұрын
@@RamKumar-kz8gg thanks for the motivation bro...🤟
@JackkofAll3 жыл бұрын
Raj bhaiya is there a discussion group for your channel on telegram ? If not please create one , it would be great to discuss stuff among all of us
@takeUforward3 жыл бұрын
link me h na
@VishalKumar-xm5ue3 жыл бұрын
I have a doubt given this question: 1st in technical round : If the company wants a "coder" then y cant we use "pow" function 2nd in interview round: If the interviewer asks and we write him 2 lines code of using same "pow" will he be like no i want some other technique?(I assume they will ask....because i havent faced too many interviews yet...
@bhupeshbhatt48492 жыл бұрын
Can anyone explain why we have set low = mid and high = mid and not low = mid +1 and high =mid -1
@VivekKumar-zo7kr2 жыл бұрын
lets suppose from striver explanation, mid was 14. so he not moved to mid-1 which is 13 because 13.1 to 13.9 might also be a possible answer. in the same way, lets suppose mid was 3 and if we had moved to mid-1 i.e. 2, then we will not be able to access 2.1 to 2.9 which might be an answer..
@pk4288 Жыл бұрын
@@VivekKumar-zo7kr Thanks for this explanation.. I was not able to get this part :)
@namanchandak1532 Жыл бұрын
My this code require less no of calculations because whenever I found the number I am going to return it And in your code if 'l' pointer is on the ans then your *r* first approach to the pointer then it will leave the while loop and again calculate the ans then it will return int NthRoot(int n, int m) { // Write your code here. int l=1,r=m; while(l