The most common interview question for programmers[English/German]

in #programming6 years ago (edited)

English:

When you want to apply for a job as a programmer, you'll have to go through an interview in which your general knowledege aswell as programming knowledge will be tested. Interestingly, the second one will nearly every time be tested with the same exersice.

What is thise exercise about?

Normaly, you'll have to make a programm(based on cmd or any other console log) that plays the game FizzBuzz with itself. Your programming knowledge will then be tested on how modular you made it and how long your code is and how long you repeat yourselve.

What is FizzBuzz?

FizzBuzz is a simple game for children, where you count from one upwards and anytime a number is dividle by 3 you'll have to say Fizz instead of it (therefore do 3 or 6 equal Fizz) and everytime a number is dividble by 5 you say Buzz (therefore do 5 or 10 equal Buzz) and if a number is dividle by both you say fizzbuzz.

So now if you want to try it, pause readin this article and give it a go. The next lines will be about my solucion.

Non-modular solucion (Python):

while(i<100):

    i+=1

    if(i%3 == 0 and i%5 == 0):

        print("FizzBuzz")

    elif (i%3 == 0):

        print("Fizz")

    elif(i%5 == 0):

        print("Buzz")

    else:

        print(i)

This is good if you got the exercise without beeing told you should be able to change he number. If that's the case than you should use the:

Modular solucion(Python):

resA = "Fizz"

resB = "Buzz"

div1 = 3

div2 = 5

i = 0

maxNum = 100


while(i<maxNum):

    i+=1

    if(i%div1 == 0 and i%div2 == 0):

        print(resA+resB)

    elif (i%div1 == 0):

        print(resA)

    elif(i%div2 == 0):

        print(resB)

    else:

        print(i)

In this solucion you can even change the max number the numbers to divide through or what the text should say.

Here is an example of the numbers from one to 15 by the way:

1;2;Fizz;4;Buzz;Fizz;7;8;Fizz;Buzz;11;Fizz;13;14;FizzBuzz

Hopefully this will help you in some way. I mean, if you are lucky this might even be part of your job interview.

German:

Wenn man sich als Programmierer bewerben will, wird man ziemlich sicher ein Job Interview durchmachen müssen, in welchem man nach Grundwissen und Programmierkenntnissen getestet wird. Interesant dabei ist jedoch, dass fast immer die selbe Aufgabe für zweiteres gestellt wird.

Worum geht es in der Aufgabe?

Im Normalfall, muss man etwas programmieren(auf der Cmd oder einem anderen Log basierend) welches mit sich selbst das spiel FizzBuzz spielt. Wie gut du im programmieren bist wird dann daran getestet, wie modular das Programm ist, wie lang es ist und wie oft sich stellen wiederhohlen.

Was ist FizzBuzz?

FizzBuzz ist ein Kinderspiel, in welchem man von 1 aufwärts zahlt. Das komplizierte daran, ist das man alle zahlen die restlos durch 3 teilbar sind(3,6,9,...) durch Fizz und alle die restlos durch 5 teilbar sind(5,10,...) durch Buzz ersetzen muss. Ist eine Zahl durch beides teilbar muss man FizzBuzz sagen.

Alles, wenn du das jetzt versuchen willst, dann mach eine kleine Pause vom lesen und komm danach wieder, jetzt kommen nämlich meine Lösungswege(in Python) dafür.

Nicht modularer Weg:

while(i<100):

    i+=1

    if(i%3 == 0 and i%5 == 0):

        print("FizzBuzz")

    elif (i%3 == 0):

        print("Fizz")

    elif(i%5 == 0):

        print("Buzz")

    else:

        print(i)

Dieser Weg ist für den Fall, das du nur die Aufgabe bekommst das Programm zu machen und die Zahlen später nicht ersetzbar sein müssen. Für diesen Fall brauchst du den

Modularen Weg:

resA = "Fizz"

resB = "Buzz"

div1 = 3

div2 = 5

i = 0

maxNum = 100


while(i<maxNum):

    i+=1

    if(i%div1 == 0 and i%div2 == 0):

        print(resA+resB)

    elif (i%div1 == 0):

        print(resA)

    elif(i%div2 == 0):

        print(resB)

    else:

        print(i)

Dieser Weg erlaubt es auch Divisoren die Maximalzahl und den Text der ausgegeben wird zu ändern.

Hier ist übrigens ein Beispiel was das Programm ausgibt(1-15):

1;2;Fizz;4;Buzz;Fizz;7;8;Fizz;Buzz;11;Fizz;13;14;FizzBuzz

Hoffentlich konnte dieser Post dir helfen. Wer weiß, mit etwas Glück kommt das auch in deinem nächsten Interview dran.

Sort:  

Hello,

Nice post.
How long have you been programming for?

For about 3 years now

Awesome,

I will keep watching your posts as i am just starting out and can use all the help i can get.

Probably the shortest FizzBuzz code

for(i=0;i<1e2;)
console.log((++i%3?"":"Fizz")+(i%5?"":"Buzz")||i)