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.
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 Codemyfunction(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!
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
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!
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.