Funcia
Tutorialimplementationstring

FizzBuzz List

Memory limit
256 MB
Correctness time limit
10000 ms
Solvers
0
0

Count from 1 to n, but say a word instead of some numbers:

  • a multiple of both 3 and 5 (of 15): "FizzBuzz"
  • otherwise a multiple of 3: "Fizz"
  • otherwise a multiple of 5: "Buzz"
  • otherwise the number itself as a string (e.g. "7")

Return everything said, in order, as a string array.

Examples

nresult
5["1", "2", "Fizz", "4", "Buzz"]
1["1"]
15["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]

Example 1 — 3 is Fizz and 5 is Buzz.

Example 2 — Only 1 is said.

Example 3 — 15 is a multiple of both: FizzBuzz.

This is a tutorial problem: there are no performance tests, just return the correct value.

Function signature

solution(n: int) → string[]

Constraints

  • 1≤1 \le n ≤1,000\le 1{,}000

Expected complexity

Time
O(N)
Space
O(N)

Examples

nExpected
5["1","2","Fizz","4","Buzz"]
1["1"]
15[ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz" ]

Hint

Hint

Test the multiple-of-15 case first; otherwise 15 would become "Fizz". Number to string: str(i) in Python, std::to_string(i) in C++, String.valueOf(i) in Java.

Time limits per language

LanguageEfficiency time limit
C (GCC, gnu17)200 msestimated
C++ (GCC, gnu++23)200 msderived
Python 3.131000 msderived
Java 251000 msderived
Kotlin 2.4 (JVM)1200 msestimated
C# 14 (.NET 10)1200 msestimated

Test groups

GroupWeightTestsVisibility
sample03inputs and outputs
correctness10010verdict only
Loading editor…
Log in to run or submit code.

No result yet. Run or submit your code.