Problema
Flip the right triangle: the first row is the longest, with n stars, and each following row has one star fewer, down to a single *. Counting the outer loop down instead of up is the whole trick.
Implement inverted_right_triangle(n).
Input
n: The number of rows.
Output
Return the rows from top to bottom. Row i (counting from 1) has n − i + 1 * characters.
Restrições
0 ≤ n ≤ 100
Exemplos
Entrada:
n = 4
Saída esperada:
expected = ["****", "***", "**", "*"]
Entrada:
long long n = 4;
Saída esperada:
std::vector<std::string> expected = {"****", "***", "**", "*"};
Entrada:
long n = 4;
Saída esperada:
string[] expected = new string[] {"****", "***", "**", "*"};
Explicação
Rows shrink by one star: "****", "***", "**", "*".
Entrada:
n = 1
Saída esperada:
expected = ["*"]
Entrada:
long long n = 1;
Saída esperada:
std::vector<std::string> expected = {"*"};
Entrada:
long n = 1;
Saída esperada:
string[] expected = new string[] {"*"};
Explicação
With one row the triangle is just ["*"].
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
Let the outer loop count down from n to 1.
Dica 2
Each row has as many stars as the current loop value.
Dica 3
When n is 0, return an empty list.
Complexidade esperada
O(n^2) time, O(n^2) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.