Count Up II

You are given an integer N. Using recursion, print all integers from 1 to N in increasing order .

Print consecutive integers separated by a single space. Do not print a trailing space after N. Print a newline character after the complete sequence.

Note:

A normal iterative solution will pass the test cases, but the goal of this problem is to solve it using recursion and strengthen your understanding of recursive calls and base cases.

Example 1:

Input: N = 5

Output: 1 2 3 4 5

Explanation: Starting from 1, recursively include each integer until 5 is reached.

Example 2:

Input: N = 1

Output: 1

Explanation: Since N is 1, the sequence contains only 1.

Now Your Turn!

Pick the correct output for the given input

Input: N = 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= N <= 20

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
void countUp(int N) {
// Your code goes here
}
};
Test Case

Input:

N