Recursion Practice questions 2022(DSA)

Recursion Practice questions 2022



EASY:

Q1. Problem Description:

Given two integers M & N, calculate and return their multiplication using recursion. You can only use subtraction and addition for your calculation. No other operators are allowed.


Sample Input :

5

Sample Output: 15


Q2. Problem Description:

Given an integer N, count and return the number of zeros that are present in the given integer using recursion.

Sample Input: 708000

Sample Output: 4


Q3. Problem Description:

Write a recursive function that returns the sum of the digits of a given integer.


Sample Input:12345

Sample Output:15


Q4. Problem Description:

Given the code to find out and return the number of digits present in a number recursively. But it contains a few bugs, that you need to rectify such that all the test cases should pass.

Sample Input:156

Sample Output :3


MEDIUM:

Q1. Problem Description:

Given k, find the geometric sum i.e.

1 + 1/2 + 1/4 + 1/8 + ... + 1/(2^k)


Sample Input : 3

Sample Output: 1.875


Q2. Problem Description:

Check whether a given String S is a palindrome using recursion. Return true or false.


Sample Input: racecar

Sample Output: true


Q3. Problem Description:

Given a string, compute recursively a new string where all appearances of "pi" have been replaced by "3.14".


Sample Input:xpix

Sample Output:x3.14x


Q4. Problem Description:

Given a string, compute recursively a new string where all 'x' chars have been removed.


Sample Input:xaxb

Sample Output: ab

Post a Comment

0 Comments

Ad Code

Responsive Advertisement