'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-e5s3 ай бұрын
amazing! I finally understood the iterative approach
@yogitajoshi7218 Жыл бұрын
Thank you soo much sir. Amazing Explanation🙌
@ajaygonepuri2285 Жыл бұрын
Great Explanation!
@chakravarthybatna1589 Жыл бұрын
great explanation;
@rahulsharma15 Жыл бұрын
Nice thanks for sharing
@anshumaan1024 Жыл бұрын
nice explanation
@techdose4u Жыл бұрын
Thanks and welcome
@Bkmap6 ай бұрын
can you please tell me which software are you using in this video to teach .
@franly6569 ай бұрын
Great!
@GameplayRoudie Жыл бұрын
how can double hold big value in "ans" variable? it will overflow
@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
@ToanPham-wr7xe3 ай бұрын
😮
@prathmeshkhandare6113Ай бұрын
Why we not using x**n Or pow function ?
@techdose4uАй бұрын
that will multiply X n times
@prathmeshkhandare6113Ай бұрын
@@techdose4u thats what we want , and also the time complexity is also less
@btengaming48992 ай бұрын
where is the code of even exponent
@techdose4u2 ай бұрын
Please do dry run on the given code for both odd & even.
@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.