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
Build the list by stepping downward from the starting number until you reach 1.
Suggerimento 2
Generate each entry as text, then append the final farewell message at the end.
Suggerimento 3
Remember the smallest input can skip the numeric loop and still return only the farewell.
Complessità attesa
O(start) time, O(start) extra space
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.