Foundations Loops through pattern printing
10. Inverted Right Triangle of Numbers
Easy
Given an integer n, return the pattern below as a list of rows, top row first. Each row is a list of the
numbers in it, from left to right.
1 2 3 4
1 2 3
1 2
1
The pattern has n rows; the picture shows n = 4. The top row holds the numbers from 1 to n in increasing
order. Each row below it loses its last number, so the bottom row is just 1. For n = 4 the answer is
[[1,2,3,4],[1,2,3],[1,2],[1]].
Example 1
Input: n = 4
Output:
1 2 3 4 1 2 3 1 2 1
Example 2
Input: n = 1
Output:
1Example 3
Input: n = 11
Output:
1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Check your understanding
Work out the answer for this input before you write any code.
n = 3
Constraints
1 ≤ n ≤ 100
Clarifying questions
What you would ask an interviewer before writing any code.