Binary Exponentiation | Pow(x,n) | Leetcode #50

  Рет қаралды 8,834

Techdose

Techdose

Күн бұрын

Пікірлер: 24
@hiteshbhandari7009
@hiteshbhandari7009 Жыл бұрын
'Squaring the base and taking half of the exponential' - You summed up the algorithm very well :)
@Sranju23
@Sranju23 9 ай бұрын
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-e5s
@Martinnnnnn-e5s 3 ай бұрын
amazing! I finally understood the iterative approach
@yogitajoshi7218
@yogitajoshi7218 Жыл бұрын
Thank you soo much sir. Amazing Explanation🙌
@ajaygonepuri2285
@ajaygonepuri2285 Жыл бұрын
Great Explanation!
@chakravarthybatna1589
@chakravarthybatna1589 Жыл бұрын
great explanation;
@rahulsharma15
@rahulsharma15 Жыл бұрын
Nice thanks for sharing
@anshumaan1024
@anshumaan1024 Жыл бұрын
nice explanation
@techdose4u
@techdose4u Жыл бұрын
Thanks and welcome
@Bkmap
@Bkmap 6 ай бұрын
can you please tell me which software are you using in this video to teach .
@franly656
@franly656 9 ай бұрын
Great!
@GameplayRoudie
@GameplayRoudie Жыл бұрын
how can double hold big value in "ans" variable? it will overflow
@SK-qn5ry
@SK-qn5ry Жыл бұрын
Does anyone took techdose DSA course 0:31? How much it costs? What is timings of live classes?
@jawwadakhter5261
@jawwadakhter5261 Жыл бұрын
Bro techdose ke playlist me videos hai, usme dekho sab bataya hai
@ToanPham-wr7xe
@ToanPham-wr7xe 3 ай бұрын
😮
@prathmeshkhandare6113
@prathmeshkhandare6113 Ай бұрын
Why we not using x**n Or pow function ?
@techdose4u
@techdose4u Ай бұрын
that will multiply X n times
@prathmeshkhandare6113
@prathmeshkhandare6113 Ай бұрын
@@techdose4u thats what we want , and also the time complexity is also less
@btengaming4899
@btengaming4899 2 ай бұрын
where is the code of even exponent
@techdose4u
@techdose4u 2 ай бұрын
Please do dry run on the given code for both odd & even.
@rahulchoudhary414
@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
@kidoo1567 Жыл бұрын
Use long data type..
@bibhabpanda
@bibhabpanda Жыл бұрын
after result=result*x; write m=m-1;
@developer_save
@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.
Minimum Obstacle Removal to Reach Corner | Leetcode 2290
16:38
POW(x,n) | Binary Exponentiation | Leetcode
8:10
take U forward
Рет қаралды 236 М.
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 17 МЛН
How to Achieve More in 1 Month than Most People Do in 12 Months...
6:01
NVIDIA’s New AI: Stunning Voice Generator!
6:21
Two Minute Papers
Рет қаралды 89 М.
Scramble string | Dynamic Programming | MCM | Leetcode #87
23:44
Why is Python 150X slower than C?
10:45
Mehul - Codedamn
Рет қаралды 23 М.
Maximum Matrix Sum | Leetcode 1975
12:33
Techdose
Рет қаралды 1,9 М.
Towers of Hanoi: A Complete Recursive Visualization
21:13
Reducible
Рет қаралды 493 М.
Rolling hash | Rabin karp algorithm | Pattern searching
13:09
Techdose
Рет қаралды 107 М.
How many people are in the changing room? #devil #lilith #funny #shorts
00:39