DSA problem
Number Pyramid (1, 12, 123, ...)
Given an integer N, print a pattern where row i contains the numbers from 1 up to i.
This is a simple variation of the right-angled triangle: instead of repeating the same character, you print incrementing numbers within each row. Row 1 is 1, row 2 is 1 2, row 3 is 1 2 3, and so on.
The key idea is that the inner loop counter itself becomes the value you print. Your loop variable is not just controlling repetition - it is the data.
Examples
Example 1
Input:
N = 5Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5Explanation: Row i lists the numbers 1 through i, separated by single spaces.
Constraints
- 1 <= N <= 9
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.