Print 1 To N Without Using Loops Geeks For Geeks

 Problem Link:


https://practice.geeksforgeeks.org/problems/print-1-to-n-without-using-loops3621/1


Solution:


class Solution{

    static void printTillN(int n){

        if(n==0){

            return ;

        }

        else{

            printTillN(n-1);

            System.out.print(n+" ");

        }

        // code here

    }

}


Time Complexity: O(N)[GFG Time: 0.5/2.0]

Space Complexity:O(1)

Auxillary Space:O(N)[Recusive Stack of max N+1 functional calls][Non-Tail Recursive]

Total Test Cases: 200

Approach:


We, Will, apply for Recursion.

Here base condition will be when n==0 else we will make a recursive call and print number later.


"Thanks For Reading.😇"

"Share Further To Increase Knowledge Treasure.😊" 




Comments

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks