Print numbers from N to 1 (space separated) without the help of loops.
Example 1:
Input:
N = 10
Output: 10 9 8 7 6 5 4 3 2 1
Your Task:
This is a function problem. You only need to complete the function printNos() that takes N as parameter and prints number from N to 1 recursively. Don't print newline, it will be added by the driver code.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N) (Recursive).
Constraint
1<=n<=1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Complete search

Starter code: #User function Template for python3



class Solution:

    def printNos(self, n):

        # Code here

Solutions:
class Solution:

	def printNos(self, n):
		if n == 0:
			return
		print(n, end=' ')
		self.printNos(n - 1)


class Solution:

	def printNos(self, n):
		if n == 1:
			print(n, end=' ')
			return
		else:
			print(n, end=' ')
			self.printNos(n - 1)


class Solution:

	def printNos(self, n):
		if n >= 1:
			print(n, end=' ')
			self.printNos(n - 1)


class Solution:

	def printNos(self, n):

		def f(n):
			if n > 0:
				print(n, end=' ')
				f(n - 1)
		f(n)


class Solution:

	def printNos(self, n):
		for i in range(n, 0, -1):
			print(i, end=' ')


class Solution:

	def printNos(self, n):
		i = 1
		ob.prints(i, n)

	def prints(self, i, n):
		if i > n:
			return
		self.prints(i + 1, n)
		print(i, end=' ')


class Solution:

	def printNos(self, N):
		if N == 0:
			return 0
		else:
			print(N, end=' ')
			self.printNos(N - 1)


class Solution:

	def printNos(self, n):

		def backtrack(i, n):
			if i > n:
				return
			backtrack(i + 1, n)
			print(i, end=' ')
		backtrack(1, n)