L5. Power Exponentiation | Maths Playlist

  Рет қаралды 18,309

take U forward

take U forward

Күн бұрын

Notes/Codes/Problem links under day 8 of A2Z DSA Course: takeuforward.org/strivers-a2z...
Entire playlist: • Maths Playlist | Langu...
Follow us on our other social media handles: linktr.ee/takeuforward

Пікірлер: 37
@pardhi8959
@pardhi8959 4 ай бұрын
This man is the top person in youtube to provide high quality content
@drishtirai864
@drishtirai864 4 ай бұрын
For LEETCODE : (Covering all the Corner Cases) class Solution { public double myPow(double x, int n) { double ans = 1; double oriNum = n; if(x == 0 || x == 1) return x; if(n < 0){ x = 1/x; n = -(n+1); //for Integer.MIN_VALUE ans = ans * x; } while(n > 0) { if(n % 2 == 1) { ans = ans * x; n = n-1; } else { n = n/2; x = x * x; } } return ans; } }
@clanguage7730
@clanguage7730 2 ай бұрын
int a,x; // a is base and x is power cin>>a>>x; int ans =1; while(x>0){ if(x&1)ans = ans*a; a = a*a; x>>=1; } cout
@trailblazer555
@trailblazer555 Ай бұрын
I'm improving my logical thinking for problem solving by your teaching only.
@tusharmahajan7754
@tusharmahajan7754 2 ай бұрын
for overflow scenario's just use an unsigned right shift n>>>=1 is equal to n/2. why unsigned not signed right shift let say in case of number like -2147483648 if u take an abs it will -2147483648 same number again and then if you divide by 2 or signed right shift this number will be going forever negative, reason in signed right shift it replaces left vacated bits with 1 eventually you number will become -1111111....11111 in form of bits and forever loop, in this in case of unsigned right shift >>> it will fill vacated left values to zero so it will never overflow and eventually become 0 all the other code keep same make n = n/2 to n>>>=1 you will cover all cases :)
@stith_pragya
@stith_pragya 3 ай бұрын
UNDERSTOOD....Thank You So Much for this wonderful video................🙏🏻🙏🏻🙏🏻🙏🏻
@kunal7433
@kunal7433 4 ай бұрын
Brother please next string playlist if possible 🙂
@moneyonline5299
@moneyonline5299 Ай бұрын
class Solution { public: double myPow(double x, int n) { int pow = abs(n); double ans = 1; while(pow > 0) { if(pow %2 == 0) { x=x*x; pow /=2; } else { ans *=x; pow = pow -1; } } if(n < 0) ans = 1/ans; return ans; } };
@studentchampion718
@studentchampion718 3 ай бұрын
please also complete String Playlist.(This topic is more import for third college placement and it is more demanding topic for all guys.
@AkshitChaudhary-vx8iw
@AkshitChaudhary-vx8iw 4 ай бұрын
Here is the Code for the negative power : public static double pow(int x, int n) { // Handle negative exponent if (n < 0) { // Calculate positive exponent result return 1.0 / pow(x, -n); } int result = 1; while (n > 0) { if (n % 2 == 1) { result *= x; n--; } else { n /= 2; x *= x; } } return result; }
@saisardesai5548
@saisardesai5548 3 ай бұрын
x and result should be double too
@reddygopichand2002
@reddygopichand2002 4 ай бұрын
Understood ❤
@ArpitaChoudhury_00
@ArpitaChoudhury_00 Ай бұрын
Thank_You✨
@abhinanda7049
@abhinanda7049 4 ай бұрын
understood
@dhruvvekariya2342
@dhruvvekariya2342 4 ай бұрын
Can you discuss about corner case
@abhinavnarula7300
@abhinavnarula7300 4 ай бұрын
I have a small doubt, why does the last approach work, if someone can provide the intitution it will be super helpful.
@user-co9ir1wg6y
@user-co9ir1wg6y 2 ай бұрын
Understood
@Adarsh_agrahari
@Adarsh_agrahari 3 ай бұрын
❤❤
@AkshitChaudhary-vx8iw
@AkshitChaudhary-vx8iw 4 ай бұрын
@striver Code will not work for negative power! BTW Thanks sir for the video❤
@ryuu5768
@ryuu5768 4 ай бұрын
Bhai wahi if negative interger h to -2147 ..... P positive krne p int flow hora
@sysfailureexe6038
@sysfailureexe6038 2 ай бұрын
US
@hritikminmuley1397
@hritikminmuley1397 4 ай бұрын
// for posititve/negative powers public static double exponent(int x, int n) { double ans = 1; int m = n; if(n 0) { if (n % 2 == 1) { ans = ans * x; n = n - 1; } else { n = n / 2; x = x * x; } } if(m
@ryuu5768
@ryuu5768 4 ай бұрын
bro isme int overflow hoga if we multiply n*-1
@hritikminmuley1397
@hritikminmuley1397 4 ай бұрын
@@ryuu5768 That is for converting the power to positive.
@ryuu5768
@ryuu5768 4 ай бұрын
@@hritikminmuley1397 hn but wo out of int limit hojyega for a test case for n=-214........ Something
@deepalikumari5319
@deepalikumari5319 4 ай бұрын
Code for Negative powers is not running.please help
@AkshitChaudhary-vx8iw
@AkshitChaudhary-vx8iw 4 ай бұрын
yes because our while will never run because n is negative so our code will simply return 1/ ans (which is 1);
@deepalikumari5319
@deepalikumari5319 4 ай бұрын
@@AkshitChaudhary-vx8iw how can we fix it?
@bishalkundu7592
@bishalkundu7592 4 ай бұрын
@@deepalikumari5319 return 1 / pow(x, -n)
@Manish-rr3nc
@Manish-rr3nc Ай бұрын
Bhai code kaha hai striver A - Z sheet mein lec 4 mein toh nhi dikh raha please batado
@AkshitChaudhary-vx8iw
@AkshitChaudhary-vx8iw Ай бұрын
Here is the Code for the negative power : public static double pow(int x, int n) { // Handle negative exponent if (n < 0) { // Calculate positive exponent result return 1.0 / pow(x, -n); } int result = 1; while (n > 0) { if (n % 2 == 1) { result *= x; n--; } else { n /= 2; x *= x; } } return result; }
@chiragbansod8252
@chiragbansod8252 4 ай бұрын
understood
@hardikpatel352
@hardikpatel352 Ай бұрын
understood
@havefunwithshort
@havefunwithshort Ай бұрын
understood
@shaiksoofi3741
@shaiksoofi3741 Ай бұрын
understood
L6. Sieve of Eratosthenes | Maths Playlist
18:27
take U forward
Рет қаралды 31 М.
solving a logarithmic equation with different bases
4:10
blackpenredpen
Рет қаралды 348 М.
Эффект Карбонаро и нестандартная коробка
01:00
История одного вокалиста
Рет қаралды 10 МЛН
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 25 МЛН
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 66 МЛН
L4. Print all prime factors of a Number | Maths Playlist
18:53
take U forward
Рет қаралды 28 М.
Binary Exponentiation
15:13
Errichto Algorithms
Рет қаралды 97 М.
Water powered timers hidden in public restrooms
13:12
Steve Mould
Рет қаралды 737 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
L12. Minimum Window Substring | 2 Pointers and Sliding Window Playlist
27:06
Binary Exponentiation | Pow(x,n) | Leetcode #50
10:09
Techdose
Рет қаралды 7 М.
but what is 'a lifetime?
12:20
leddoo
Рет қаралды 64 М.
Programming with Math | The Lambda Calculus
21:48
Eyesomorphic
Рет қаралды 161 М.