Power of Four | LeetCode 342 | C++, Java, Python

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

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

August LeetCoding Challenge | Problem 4 | Power of Four | 4 August,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Power of Four,
Power of Four c++,
Power of Four Java,
Power of Four python,
Power of Four solution,
342. Power of Four,

#CodingInterview #LeetCode #AugustCodingChallenge #Google #Amazon #bitmanipulation #PowerOfFour
Рекомендации по теме
Комментарии
Автор

Amazing, I've learned so much from you. Thank you so much for all of your content.

crisag.
Автор

Improved audio quality, presentation and explanation method. This man is on a roll.
Keep Making !

acxd
Автор

Thanks for this video. Great explanation.

akshatmathur
Автор

Very nicely explained!! Thank you so much.

singhrav
Автор

Wake up at morning...watch knowledge center daily leetcode challenge videos..do extra questions on leetcode...go to sleep

raviashwin
Автор

Thank you. None has reached your level at explaining leetcode so far.

mohammadyahya
Автор

very helpful! thank you for the great explanation

jacksonwahl
Автор

use log function
class Solution:
def isPowerOfFour(self, num):
import math
if num>0:
a=math.log(num)/math.log(4)
b=a-int(a)
else:
return False
if b==0:
return True

mohitarora
Автор

Please add #bitmanipulation so that searching all bit manipulation videos will be easy

Starfalll
Автор

My Solution
Time- O(1), Space- O(1)
bool isPowerOfFour(int num) {
if(num <= 0)
return false;
int val1 = floor(log2(num)), val2 = ceil(log2(num));
if(val1 != val2)
return false;
return !(val1&1);
}

rishisharma
Автор

Bro where should I focus on codeforces or codechef

manu-singh
Автор

can we take log (base 4) in c++....if yes then how

shivanktripathi
Автор

class Solution {
public:
bool isPowerOfFour(int num1) {
if(num1 == 1)
return true;
long long int num = num1;
if((num & num - 1) == 0 && (num % 10 == 4 || num%10 == 6 ))
return true;
return false;
}
};
Explanation:
each power of 4 has either 4 or 6 one's digit. And power(4) is a subset of power(2) and we can solve power(2) as (n & n-1) == 0 and check whether it has units digit 4 and 6

deepakkumarsahu
Автор

what is "x" in dont mind im yet a beginner hoping for clarification of this doubt

pillabindu
Автор

try:
return int(math.log(num, 4)) == (math.log(num, 4))
except ValueError:
pass

midhileshmomidi
Автор

return (num>0 && (num & (num-1)) == 0 && (int)log2(num) % 2 == 0);

JardaniJovonovich
welcome to shbcf.ru