Power of Four - LeetCode Interview Coding Challenge [Java Brains]

preview_player
Показать описание
In this video we will learn two different solutions to solve the power of four Leetcode problem

Interview Question: Given an integer (signed 32 bits), write a function to check whether it is a power of 4.

Difficulty level: Easy
Language: Java

Welcome to the Java Brains Java Interview challenge series of videos where we tackle various coding challenges ranging from the beginner level to advanced level - especially in the context of coding interviews.

Any coding problems you would like me to explore? Please let me know in the comments what you think!

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

Everything come down to how strong are your basics and fundamentals. Beatifully explained....

vivekrmishra
Автор

With a 32 bit number, the easiest and fastest approach is of course to simply pre-calculate all ~16 possible values.

alexsteb
Автор

If it is 4^x, you could test it with a binary solution. You could check if the binary representation of the number is 1 followed by an odd number of zeros.

danthest
Автор

You explain so well and make it easy. You have got great teaching skills

Priya_
Автор

Everytime Koushik says 4, take a shot! 😂

jonsnow
Автор

You can't avoid the check while (n!=1) instead of while (n!=4) since n!=4 would fail for input =1.
Again, the logarithmic solution for power of 3 has to be tweaked a bit for explicitly mentioning the base which is by default e.

//works for power of 3 or any number

dipakkumarrai
Автор

Hi Kaushik
Thanks for another knowledge byte
I admire your knowledge as much as your teaching style

Cheers

inderkalra
Автор

This is my approach to solve this question : in constant time o(1): (n&(n-1)==0) && n%3==1

praveenj
Автор

probably though the division of 4 method is faster than the calcualtion of log4/logx but its nice to remember some math :)

funprog
Автор

We all waiting kubernates tutorials from you 😍😘

Togrul
Автор

Just a footnote x^0 = 1 .... so 1 as input should return true

inderkalra
Автор

Supper. Really like your way of explanation.

SureshDoppalapudi
Автор

Nice that brute forced is also discussed at start. Can you discuss the bit level solution ?

sunny-
Автор

Write a java code on
* Take two input strings string1 and string2
* Remove the string2 from string1 (remove it in all postions that occur in string1) and print remaining string1
* Should not use predefined functions of string
* Example input string1 = "another", string2 = "the"
* Output = anor
Sir can you please help me to get this code and tell as many approach we can use, this question was asked me in an interview so please help me sir

manojkumarjayanthi
Автор

I have 2 alternative :
public boolean isPowerOfFour(int i) { return -> c != '0');}
public boolean isPowerOfFour(int i) { return -> c-'0').sum() == 0;}

viktors.
Автор

Kousik how to be like you ?
I mean how you learn things so

virusehwag
Автор

what is the time-complexity of the logarithmic function in java?

etienneonasch
Автор

And I was going with the divisibility rule.

Divisibility of 4 says a number is only divisible by 4 if the last 2 digits of the number are divisible by 4.
So I'd extract the last 2 digits and check by dividing by 4 but that' not as efficient as the solution you explained.

ShinAkuma
Автор

Kaushik would love u to get connected to u through linkedin...How about dropping the link in the description of u r videos...Hope u consider it

ManojKumar-sokw
Автор

could you explain someone, why there is while( n ! = 1) {
i didnt get that(
what is the meaning of this?

aislofi
join shbcf.ru