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

  • @hiteshbhandari7009
    @hiteshbhandari70099 ай бұрын

    'Squaring the base and taking half of the exponential' - You summed up the algorithm very well :)

  • @Sranju23
    @Sranju235 ай бұрын

    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.

  • @yogitajoshi7218
    @yogitajoshi721811 ай бұрын

    Thank you soo much sir. Amazing Explanation🙌

  • @ajaygonepuri2285
    @ajaygonepuri2285 Жыл бұрын

    Great Explanation!

  • @rahulsharma15
    @rahulsharma15 Жыл бұрын

    Nice thanks for sharing

  • @chakravarthybatna1589
    @chakravarthybatna15898 ай бұрын

    great explanation;

  • @franly656
    @franly6565 ай бұрын

    Great!

  • @GameplayRoudie
    @GameplayRoudie Жыл бұрын

    how can double hold big value in "ans" variable? it will overflow

  • @user-mo6nk1xp1p
    @user-mo6nk1xp1p2 ай бұрын

    can you please tell me which software are you using in this video to teach .

  • @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

  • @anshumaan1024
    @anshumaan1024 Жыл бұрын

    nice explanation

  • @techdose4u

    @techdose4u

    Жыл бұрын

    Thanks and welcome

  • @rahulchoudhary414
    @rahulchoudhary41410 ай бұрын

    '''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

    10 ай бұрын

    Use long data type..

  • @bibhabpanda

    @bibhabpanda

    10 ай бұрын

    after result=result*x; write m=m-1;

  • @developer_save

    @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.