Retour aux défis
Facile 0 résolus 0 % de réussite

Countdown to Liftoff

Count down from a number and end with Liftoff!

Ce que vous allez apprendre

  • Count down with a loop
  • Mix numbers and text in a list
  • Stop at the right value

Problème

Afficher la traduction

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

Exemple 1
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!".

Exemple 2
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.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.