Count Down II

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

Print consecutive integers separated by a single space. Do not print a trailing space after 1. 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: 5 4 3 2 1

Explanation: Starting from 5, recursively print each integer in decreasing order until 1 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 countDown(int N) {
// Your code goes here
}
};
Test Case

Input:

N