You are given an integer n. Your task is to print all the numbers starting from 1 up to n. The solution must be implemented using recursion only, and you are not allowed to use any looping constructs such as for or while.
All the numbers should be printed in increasing order, on a single line, with each number separated by a space.
Example 1
Input: n = 15
Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Explanation: Not Needed
Example 2
Input: n = 5
Output: 1 2 3 4 5
Explanation: Not Needed
Example 3
Input: 2
Output: 1 2
Explanation: Not Needed
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
5
1 2 3 4 5
7
1 2 3 4 5 6 7