JB TAK FODEGA NHI .... TB TK CHODEGA NHI .... (MAANG)

L4 Problems on Functional Recursion

In this Lecture we Pratice Some problems that Based on the Functional Recursion.

  • Reverse the Array
  • Check the String is the Palandrome or Not
  • We have a Given an array and out task is the Reverse the Array using the Recursion

    Example 1:
    Input: nums = [1,2,3,4,5,6,7,8,9,10]
    Output: [10,9,8,7,6,5,4,3,2,1]

    We used the Concept of the Two Pointer Approch and swap the both element.

    Sudo Code
                        myfunction(index){
                            if (index >= n // 2){
                                return;
                            }
                            swapFunction(arr[index],arr[n-index-1])
                            myfunction(index+1)
                        }
                      
    Recursion Tree


    Notes

    Note: Zoom for Better Understanding



    Code Zone!

    Reverse Array Recursion Python Code
    Reverse Array Recursion Java Code
    Reverse Array Recursion C++ Code
    Sb Mai He Kru ...

    Khud Bhi Kr le Khuch ..... Nalayk


    Time Complexity:O(N) Linear Time for the Iteration.
    Space Complexity:O(N) O(N) for the Recursive Stack Space.


    we have a Given string and our task is chek given string is Palandrome or not.

    Example 1:
    Input: str = mam
    Output: Yes

    str = Prince
    Output: No

    Again we used the Concept of the two pointer that we learn Prevesiolly.

    Sudo Code
                        myfunction(index,string){
                            if (index >= n // 2){
                                return;
                            }
                            if (string[index] != string[n-index-1]){
                                return false
                            }
                            return myfunction(index+1,string)
                            
                        }
                      

    Code Zone!

    Palandrome String Recursion Python Code
    Palandrome String Recursion Java Code
    Palandrome String Recursion C++ Code
    Sb Mai He Kru ...

    Khud Bhi Kr le Khuch ..... Nalayk


    Time Complexity:O(N) Linear Time for the Iteration.
    Space Complexity:O(N) O(N) for the Recursive Stack Space.


    Color
    Background
    Interview Docs File "All the Best" Team @DSAwithPrinceSingh

    ~ It's All About Consistency📈 Dedication🎯 HardWork💪 Happy Coding❤️ ~