Tutte le sfide
Facile 4 risolte 100.0% di accettazione

Countdown to Liftoff

Count down from a number and end with Liftoff!

Cosa imparerai

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

Problema

Mostra traduzione

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

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

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

La migliore soluzione superata di ogni programmatore. Le più veloci, leggere e meglio valutate stanno in alto.

# Programmatore Linguaggio Tempo Memoria Voto dell'IA Soluzione
1 RCRiccardo Corti Python 700 ms - 5/5 Vedi il codice
2 HJhettory Jurash Python 712 ms - 5/5 Vedi il codice
3 LMLaura Mahlow Python 722 ms - 5/5 Vedi il codice
4 ДЗДавид Зайдулин Python 739 ms - 5/5 Vedi il codice

Impara dagli altri

Soluzioni della community

Attenzione spoiler: 4 soluzioni complete sotto Prova prima a risolverla da solo. Puoi comunque sbirciare il codice degli altri sviluppatori e le revisioni dell'IA. Accedi e risolvi la sfida per partecipare alla discussione.