Print GFG n times without the loop.
Example:
Input:
5
Output:
GFG GFG GFG GFG GFG
Your Task:
This is a function problem. You only need to complete the function printGfg() that takes N as parameter and prints N times GFG 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 printGfg(self, n):

        # Code here

Solutions:
class Solution:

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


class Solution:

	def printGfg(self, n):
		l = ['GFG'] * n
		print(*l, end=' ')


class Solution:

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


class Solution:

	def printGfg(self, n):
		print(N * 'GFG ', end=' ')


class Solution:

	def printGfg(self, n):

		def help(n, a='GFG'):
			if n == 0:
				return
			else:
				print(a, end=' ')
			help(n - 1)
		help(n)


class Solution:

	def printGfg(self, n):
		for i in range(n):
			print('GFG', end=' ')


class Solution:

	def printGfg(self, n):

		def printgfg(i):
			if i == n + 1:
				return
			print('GFG', end=' ')
			printgfg(i + 1)
		printgfg(1)