Binary Exponentiation | Pow(x,n) | Leetcode #50
This video explains the most optimal technique to find pow(x,n) using the binary exponentiation technique. We have shown you the bruteforce followed by the optimal technique. We will learn binary exponentiation from scratch. This is one of the most important math algorithm and a very frequently asked interview problem.
CODE LINK is present below as usual. If you find any difficulty or have any queries then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
======================================PLEASE DONATE=============================
🧡 SUPPORT OUR WORK: / techdose
💚 UPI-ID: surya.kahar@ybl
💞JOIN Membership: / @techdose4u
==============================================================================
INSTAGRAM : / surya.pratap.k
LinkedIn: / surya-pratap-kahar-47b...
WEBSITE: techdose.co.in/
TELEGRAM Channel LINK: t.me/codewithTECHDOSE
TELEGRAM Group LINK: t.me/joinchat/SRVOIxWR4sRIVv5...
=======================================================================
USEFUL LINKS:
🟠Must do TIPS to ACE Virtual Interview: • 🔴Must do Tips to ACE y...
🟢Best strategy to excel your coding interview: • 🔴Best strategy to exce...
🟡Get your dream job in 1 month: • 🔴Get your dream job in...
🔵How to crack dream job in just 2 months: • How to crack dream job...
🟣7 Days DSA plan: techdose.co.in/7-days-dsa-che...
RELATED LINKS:
CODE LINK: gist.github.com/SuryaPratapK/...
Пікірлер: 17
'Squaring the base and taking half of the exponential' - You summed up the algorithm very well :)
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.
Thank you soo much sir. Amazing Explanation🙌
Great Explanation!
Nice thanks for sharing
great explanation;
Great!
how can double hold big value in "ans" variable? it will overflow
can you please tell me which software are you using in this video to teach .
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
nice explanation
@techdose4u
Жыл бұрын
Thanks and welcome
'''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
10 ай бұрын
Use long data type..
@bibhabpanda
10 ай бұрын
after result=result*x; write m=m-1;
@developer_save
9 ай бұрын
// 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 } } //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.