Problème
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!".
Contraintes
0 ≤ start ≤ 1,000
Exemples
Entrée :
start = 3
Sortie attendue :
expected = ["3", "2", "1", "Liftoff!"]
Entrée :
long long start = 3;
Sortie attendue :
std::vector<std::string> expected = {"3", "2", "1", "Liftoff!"};
Entrée :
long start = 3;
Sortie attendue :
string[] expected = new string[] {"3", "2", "1", "Liftoff!"};
Explication
"3", "2", "1", then "Liftoff!".
Entrée :
start = 0
Sortie attendue :
expected = ["Liftoff!"]
Entrée :
long long start = 0;
Sortie attendue :
std::vector<std::string> expected = {"Liftoff!"};
Entrée :
long start = 0;
Sortie attendue :
string[] expected = new string[] {"Liftoff!"};
Explication
There is nothing to count, so only "Liftoff!" remains.
Comment l'aborder
Essayez d'abord seul, puis ouvrez les indices un par un.
Indice 1
Build the list by stepping downward from the starting number until you reach 1.
Indice 2
Generate each entry as text, then append the final farewell message at the end.
Indice 3
Remember the smallest input can skip the numeric loop and still return only the farewell.
Complexité attendue
O(start) time, O(start) extra space
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.