Complexity Analysis of Fizz Buzz Program

Time Complexity: O(N), since we need to traverse the numbers from 1 to n in any condition.
Auxiliary Space: O(1)



Fizz Buzz Program in C++, Java, Python, C# & Javascript

Fizz Buzz Problem states that given an integer n, for every integer i <= n, the task is to print “FizzBuzz” if i is divisible by 3 and 5, “Fizz” if i is divisible by 3, “Buzz” if i is divisible by 5 or i (as a string) if none of the conditions are true.

Fizz Buzz Program

Example:

Input: n = 3
Output: [1 2 Fizz]

Input: n = 10
Output: [1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz]

Input: n = 20
Output: [1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz]

Similar Reads

Approach for Fizz Buzz Program:

Iterate on the given number from 1 to n, check its divisibility and add the string into result according to the given condition....

Complexity Analysis of Fizz Buzz Program:

...

Contact Us