POW(x,n) | Binary Exponentiation | Leetcode

preview_player
Показать описание

Find DSA, LLD, OOPs, Core Subjects, 1000+ Premium Questions company wise, Aptitude, SQL, AI doubt support and many other features that will help you to stay focussed inside one platform under one affordable subscription. Have a hassle free one stop solution for up-skilling and preparing.

Рекомендации по теме
Комментарии
Автор

Understood or not ? Drop a Yes or No :D ..
.
.
.

takeUforward
Автор

Bro don't end this series and please ignore dislikers and don't get demotivated as I came to know about many technique to solve same problem which I submitted in brute force approach

rishitiwari
Автор

sound quality has exponentially improved :)

abhishekkmandal
Автор

Raj bhai your placement series is really really useful for all students thanks for your efforts .

iampatelajeet
Автор

The overflow problem can be solved without using long and just writing n=abs(n). I did this and it worked fine for me.

himanshumishra
Автор

I knew this approach but it's always better to understand it from the legend. thanks for making our life easy bro ❤️

sudesh
Автор

I think there is some fault in c++ solution, the if condition is wrong

aaryannigam
Автор

My recursive solution ( accepted in leetcode )

class Solution {
public:
double func(double x, int n){
if(n==0){
return 1;
}
if(n%2 == 0){
return func(x*x, n/2);
}
else{
return x*func(x*x, n/2);
}
}
double myPow(double x, int n) {
if(n<0){
double ans = func(x, n);
return 1/ans;
}
return func(x, n);
}
};

amansinghal
Автор

Using recursion- JAVA

static double pow(double x, long n){
if(n == 0)
return 1;
if(n%2 == 0)
return pow(x*x, n/2);
else
return x*pow(x, n-1);
}

When the function returns the result, do check if n was +ve or -ve and show output accordingly.

vibhor
Автор

Nice... It is called as Fast Exponential Algorithm

I had studied it during B.Tech

extremlyextrovert
Автор

Very nice video...already knew the logn solution but the overflow condition was new which could've easily ruined the continue on this series it helps a lot

rajrangwani
Автор

this logic is just mind blowing.. I wasn't able to think in that angle

priyankavasam
Автор

Why have you kept this question in the ARRAYS section of the SDE sheet ??

ravishankar
Автор

Appreciable....your videos are helping a lot....carry on!!! 🤩🤩

kanishkanim
Автор

you didn't explain the recursive one..

studyacc
Автор

Where is this series in your channel. Please share the playlist link (placement series) here

gamingwithhemend
Автор

Brute Force

class Solution {
public double myPow(double x, int n) {
double ans = x;
if(n > 0){
for(int i=1; i<n; i++)
ans = ans * x;
}else{
for(int i=1; i>n; i--)
ans = ans / x;
}
return ans;
}
}

kaustavpaul
Автор

Don't dislike, he is doing a great job ❤ thank you bhai 😎🙌

mutyamreddybejjanki
Автор

Why this method and recursion is taking 20ms but inbuilt pow() or ** operator is taking 12 ms why the later one is fast ?

shivampurbia
Автор

UNDERSTOOD... !!!
Thanks striver for the video... :)

ranasauravsingh
visit shbcf.ru