Fizz Buzz

Problem Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz” Example of sequence - 3,6,9,12,15,18,1,24,27. Solution Method 1- Brute force Here we notice that that after 15, there is 18. So, we should increment the iterator by 2, and then 1 i. [Read More]

Fizz Buzz

Problem Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz” Example of sequence - 3,6,9,12,15,18,1,24,27. Solution Method 1- Brute force Here we notice that that after 15, there is 18. So, we should increment the iterator by 2, and then 1 i. [Read More]

The Celebrity Problem

Problem In a party of N people, only one person is known to everyone. Such a person may be present in the party, if yes, (s)he doesn’t know anyone in the party. We can only ask questions like “does A know B? “. Find the stranger (celebrity) in minimum number of questions. Solution We can describe the problem input as an array of numbers/characters representing persons in the party. [Read More]