Tutorialimplementationstring
FizzBuzz List
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 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
| n | result |
|---|---|
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
-
n
Expected complexity
- Time
- O(N)
- Space
- O(N)
Examples
| n | Expected |
|---|---|
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
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1000 ms | derived |
| Kotlin 2.4 (JVM) | 1200 ms | estimated |
| C# 14 (.NET 10) | 1200 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 100 | 10 | verdict only |