Java Interview Coding Challenge #1: FizzBuzz

preview_player
Показать описание
Welcome to a new series of videos where we tackle various coding challenges ranging from the beginner level to advanced level - especially in the context of coding interviews.

We start the series off with a very simple coding challenge - FizzBuzz.

Any coding problems you would like me to explore? Please let me know in the comments what you think!
Рекомендации по теме
Комментарии
Автор

who wants a video series on Dynamic Programming? Do reply and smash that like button.

omprakashbairagi
Автор

Appreciate ur effort to start this coding series. Kindly also put spring boot security series in ur bucket list.

chandramanigupta
Автор

How about put i%15 instead of (i%3)&&(i%5)
It will be more efficient.

For extension friendly code we can write i%(3*5)

vaibhavpatil_it
Автор

Thanks for starting this new series. We need more problems like this and correct approach when we try to solve a problem.

ssrujithreddy
Автор

The challenge isn't to write a code for the problem, it is to reduce the solution code provided in the test challenge as much as possible.

azizthanawala
Автор

instead of i % 3 == 0 && i %5 == 0 you could just write i %15 == 0

just the multiplication of the two numbers.
It's a bit shorter and more elegant code.
Thank's alot for you very good videos. You are a great teacher!

__Pathfinder__
Автор

Wow, more exciting stuff from the legend himself... #Kaushik'sNo1Fan

skullwise
Автор

String output = ((i%3)==0)? (((i%5)==0)? "FizzBuzz" : "Fizz") : (((i%5)==0)? "Buzz" : String.valueOf(i));

BharCode
Автор

This type of problem statements are fairly simple if you know how to use modulus and division arthamatic operators. People look for O(1) complexity. I came across similar problem where you need to calculate lowest number of coin required to split a given dollar amount.
Example you ill be given following coins $1, $0.25, $0.10, $0.1 and calculate least amount of coins required to split $5.58.
Outcome : 5 - $1 coins, 2 - 25 cents, 8 - 1 cent coins

ramgopal.cheedureddy
Автор

Why don't you do a series on Core Java?

poornaps
Автор

I just now found your channel...you are so much awesome bro... thanks a lot for information sharing....I highly appreciate your

madhavanrao
Автор

Great efforts Koushik, love all ur videos on spring, spring boot, Java 8, microservices. Eagerly waiting for microservicervices Level 2 series

srikanthdannarapu
Автор

This is *not* the ideal solution that interviewers look for. (Well, from what I know ). There are better ways of achieving the same result with less code and more efficiency.


The problem with this approach is it's hard to expand. So if you were to make it so that you need to print 'Fuzz' every time a multiple of 7 shows up and FizzBuzzFuzz every time a multiple of 3, 5 and 7 shows up, you need to heavily modify the code.


Something else that you could do is have a String variable called output and set it to nothing.


String output = "";


then just do this :


if(i%3 == 0), output += "Fizz";
if(i%5 == 0), output += "Buzz";


print(output);


This approach is very easy to expand and customize. Also it's much shorter and concise. So now if you need to add 2 more conditions for 7 and 11, all you need to do is add this before the print statement :


if(i%7 == 0), output += "Fuzz";
if(i%11 == 0), output += "Jazz";


I personally think this is somewhat better and you don't have to worry about the problem you mentioned in the video. Then again, both work fine. Cheers.

heksqer
Автор

Very best initiative. Programming puzzles are the most expected questions in java interview. Thanks for the series!

mayoorm
Автор

Another approach:
for(i=1;i<=100;i++) {
if(i%3 != 0 && i%5 != 0) {
System.out.println(i);
continue;
}
if(i%3 == 0)
System.out.print("Fizz");
if(i%5 == 0)
System.out.print("Buzz");

System.out.println();
}




Please let me know if i'm wrong :)

inspiration
Автор

I was wondering sometime back how it would be to get to learn how to tackle interview coding questions from you and here you are with a brand new series for the same. Kudos to you Koushik !

anshuldogra
Автор

Thank you! The way you explain is in believable:). Could you try to make a video on Big O notation?

surves
Автор

Looking forward for more complex coding questions. Thanks for starting this series.

sharidass
Автор

Please upload more problems which are complex

varunbhardwaj
Автор

Cannot thank enough to Kaushik kothagal, for crystal clear concepts, showing paths and keeping the things so exciting. His videos, together with books can make programming so much fun and ideas can keep flowing ..

deepak
join shbcf.ru