Problema
Count down from start to 1, then add "Liftoff!". Each number becomes one text entry.
Implement countdown(start).
Input
start: The number to start counting down from.
Output
Return the countdown as a list of strings, ending with "Liftoff!".
Vincoli
0 ≤ start ≤ 1,000
Esempi
Input:
start = 3
Output atteso:
expected = ["3", "2", "1", "Liftoff!"]
Input:
long long start = 3;
Output atteso:
std::vector<std::string> expected = {"3", "2", "1", "Liftoff!"};
Input:
long start = 3;
Output atteso:
string[] expected = new string[] {"3", "2", "1", "Liftoff!"};
Spiegazione
"3", "2", "1", then "Liftoff!".
Input:
start = 0
Output atteso:
expected = ["Liftoff!"]
Input:
long long start = 0;
Output atteso:
std::vector<std::string> expected = {"Liftoff!"};
Input:
long start = 0;
Output atteso:
string[] expected = new string[] {"Liftoff!"};
Spiegazione
There is nothing to count, so only "Liftoff!" remains.
Come affrontarlo
Prova prima da solo, poi apri un suggerimento alla volta.
Suggerimento 1
Costruisci la lista andando all’indietro dal numero iniziale fino a 1.
Suggerimento 2
Genera ogni voce come testo, poi aggiungi alla fine il messaggio di addio finale.
Suggerimento 3
Ricorda che l’input più piccolo può saltare il ciclo numerico e restituire solo l’addio.
Complessità attesa
tempo O(start), spazio aggiuntivo O(start)
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.