Foundations Loops through pattern printing
17. Increasing Number Triangle
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 5 6
7 8 9 10
The pattern has n rows; the picture shows n = 4. Row i, counting from 1, holds i numbers. The numbers
run 1, 2, 3, … across the whole pattern, so each row carries on from where the row above ended. For n = 4 the answer is [[1],[2,3],[4,5,6],[7,8,9,10]].
Example 1
Input: n = 4
Output:
1 2 3 4 5 6 7 8 9 10
Explanation: Each row carries on from the row above, so row 4 starts at 7 and ends at 10.
Example 2
Input: n = 1
Output:
1Example 3
Input: n = 6
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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.