Problema
For each integer from 1 through limit, use Fizz for multiples of 3, Buzz for multiples of 5, and FizzBuzz for multiples of both. Otherwise use the number written as text. Return the entries in order instead of printing them.
Implement fizz_buzz(limit).
Input
limit: The last integer to include.
Output
Return a list of strings, one for each integer from 1 through limit.
Restrições
0 ≤ limit ≤ 10,000. A limit of 0 produces an empty list.
Exemplos
Entrada:
limit = 5
Saída esperada:
expected = ["1", "2", "Fizz", "4", "Buzz"]
Entrada:
long long limit = 5;
Saída esperada:
std::vector<std::string> expected = {"1", "2", "Fizz", "4", "Buzz"};
Entrada:
long limit = 5;
Saída esperada:
string[] expected = new string[] {"1", "2", "Fizz", "4", "Buzz"};
Explicação
3 is divisible by 3 and 5 is divisible by 5. Other entries keep their number.
Entrada:
limit = 0
Saída esperada:
expected = []
Entrada:
long long limit = 0;
Saída esperada:
std::vector<std::string> expected = {};
Entrada:
long limit = 0;
Saída esperada:
string[] expected = new string[] {};
Explicação
There are no integers from 1 through 0, so the list is empty.
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
Each position depends only on the current integer’s divisibility by 3 and 5.
Dica 2
Build the result list in order by checking both divisibility conditions for every number.
Dica 3
Handle the lower bound carefully: if the limit is 0, the answer is an empty list.
Complexidade esperada
O(n) time, O(n) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.