Amazon Interview Question

🔹 7. FizzBuzz (Python) Question (reconstructed): Write a simple FizzBuzz function: Print "FizzBuzz" if divisible by 3 and 5 "Fizz" if divisible by 3 "Buzz" if divisible by 5 IMPORTANT. Here how you think about efficiency is tested as well. Check for both first, then check for 3, then for 5. Both because well logically you need that. After for 3 and not for 5 for optimization (less checks overall as more number are divisible per 3 so you never go on the divisible per 5 check.)

Interview Answer

Anonymous

Jun 23, 2025

if n % 3 == 0 and n % 5 == 0: print("FizzBuzz") elif n % 3 == 0: print("Fizz") elif n % 5 == 0: print("Buzz") else: print(n)