'Squaring the base and taking half of the exponential' - You summed up the algorithm very well :)
@Sranju239 ай бұрын
Nice explanation. However there's one edge case added on this LC problem. If given number is negative then take the absolute value but store this as long to avoid overflow. At the end return accordingly.
@Martinnnnnn-e5s2 ай бұрын
amazing! I finally understood the iterative approach
@Bkmap5 ай бұрын
can you please tell me which software are you using in this video to teach .
@yogitajoshi7218 Жыл бұрын
Thank you soo much sir. Amazing Explanation🙌
@GameplayRoudie Жыл бұрын
how can double hold big value in "ans" variable? it will overflow
@chakravarthybatna1589 Жыл бұрын
great explanation;
@ajaygonepuri2285 Жыл бұрын
Great Explanation!
@anshumaan1024 Жыл бұрын
nice explanation
@techdose4u Жыл бұрын
Thanks and welcome
@rahulsharma15 Жыл бұрын
Nice thanks for sharing
@franly6568 ай бұрын
Great!
@prathmeshkhandare611319 күн бұрын
Why we not using x**n Or pow function ?
@techdose4u19 күн бұрын
that will multiply X n times
@prathmeshkhandare611319 күн бұрын
@@techdose4u thats what we want , and also the time complexity is also less
@SK-qn5ry Жыл бұрын
Does anyone took techdose DSA course 0:31? How much it costs? What is timings of live classes?
@jawwadakhter5261 Жыл бұрын
Bro techdose ke playlist me videos hai, usme dekho sab bataya hai
@btengaming4899Ай бұрын
where is the code of even exponent
@techdose4uАй бұрын
Please do dry run on the given code for both odd & even.
@ToanPham-wr7xe3 ай бұрын
😮
@rahulchoudhary414 Жыл бұрын
'''class Solution { public double myPow(double x, int n) { //exponentiation double result=1; int m=Math.abs(n); while(m>=1){ if(m%2==1){ result=result*x; } x=x*x; m=m/2; } return (n
@kidoo1567 Жыл бұрын
Use long data type..
@bibhabpanda Жыл бұрын
after result=result*x; write m=m-1;
@developer_save Жыл бұрын
// here is the correct one class Solution { public double myPow(double x, int n) { double result = 1.0; long m = Math.abs((long) n); // Convert n to long to handle Integer.MIN_VALUE while (m > 0) { if (m % 2 == 1) { result *= x; } x *= x; m /= 2; } return (n < 0) ? 1 / result : result; } } //The issue is with the line m = m / 2;. In the exponentiation by squaring algorithm, you typically divide the exponent n by 2 in each iteration. However, in your code, you are modifying m instead of n. As a result, the algorithm won't work correctly for negative exponents.