Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views11 pages

Problems On Recursion-1

The document outlines several programming assignments related to recursion, including reversing a string, checking if a string is a palindrome, determining if the sum of digits of a number is a palindrome, predicting the outcome of a chocolate-eating contest, and calculating the minimum operations to paint a rectangular grid. Each problem includes a statement, examples, constraints, and expected time complexity. The assignments are designed to test various algorithmic skills and efficiency in coding.

Uploaded by

ajeetvikasyadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Problems On Recursion-1

The document outlines several programming assignments related to recursion, including reversing a string, checking if a string is a palindrome, determining if the sum of digits of a number is a palindrome, predicting the outcome of a chocolate-eating contest, and calculating the minimum operations to paint a rectangular grid. Each problem includes a statement, examples, constraints, and expected time complexity. The assignments are designed to test various algorithmic skills and efficiency in coding.

Uploaded by

ajeetvikasyadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

RECURSION

ASSIGNMENT - 01
16 February 2024 17:21

CREATED BY - SHIVAM BAREKAR


REVERSE STRING
23 February 2024 18:05

Problem Statement : Write a function that reverses a string. The input string is
given as an array of characters s. You must do this by modifying the input array in-
place with O(1) extra memory.

Link : https://leetcode.com/problems/reverse-string/description/

Example 1:
Input: s = ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]

Example 2:
Input: s = ["H","a","n","n","a","h"]
Output: ["h","a","n","n","a","H"]

Constraints:
1 <= s.length <= 105
s[i] is a printable ascii character.
PALINDROME STRING
23 February 2024 18:11

Problem Statement : Given a string S, check if it is palindrome or not.

Link : https://www.geeksforgeeks.org/problems/palindrome-string0817/1

Example 1 :

Input: S = "abba"
Output: 1
Explanation: S is a palindrome

Example 2 :

Input: S = "abc"
Output: 0
Explanation: S is not a palindrome

Your Task :

You don't need to read input or print anything.


Complete the function isPalindrome()which accepts string S and returns an integer value 1
or 0.

Expected Time Complexity: O(Length of S)


Expected Auxiliary Space: O(1)

Constraints :

1 <= Length of S<= 2*105


SUM OF DIGIT IS PALINDROME OR NOT
23 February 2024 18:16

Problem Statement : Given a number N.Find if the digit sum(or sum of digits) of N is
a Palindrome number or not.
Note : A Palindrome number is a number which stays the same when reversed.Example-
121,131,7 etc.

Link : https://www.geeksforgeeks.org/problems/sum-of-digit-is-pallindrome-or-
not2751/1

Example 1 :

Input:
N=56
Output:
1
Explanation:
The digit sum of 56 is 5+6=11.
Since, 11 is a palindrome number.Thus,
answer is 1.

Example 2 :

Input:
N=98
Output:
0
Explanation:
The digit sum of 98 is 9+8=17.
Since 17 is not a palindrome,thus, answer
is 0.

Your Task :

You don't need to read input or print anything.Your Task is to complete the function
isDigitSumPalindrome() which takes a number N as input parameter and returns 1 if the
Digit sum of N is a palindrome.Otherwise it returns 0.

Expected Time Complexity:O(LogN)


Expected Auxillary Space:O(1)

Constraints :

1<=N<=109
THE DEADLY SIN
23 February 2024 18:21

Problem Statement : Meliodas and Ban are fighting over chocolates. Meliodas has X
chocolates, while Ban has Y. Whoever has lesser number of chocolates eats as many
chocolates as he has from the other's collection. This eatfest war continues till either
they have the same number of chocolates, or atleast one of them is left with no
chocolates.

Can you help Elizabeth predict the total no of chocolates they'll be left with at the end of
their war?

Link : https://www.codechef.com/problems/SINS

Input Format :
First line will contain T, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, which contains two integers X,Y, the no of
chocolates Meliodas and Ban have, respectively.

Output Format :
For each testcase, output in a single line the no of chocolates that remain after Ban and
Meliodas stop fighting.

Constraints :

1≤T≤100000
0≤X,Y≤109

Sample :

Input : Output

53 2

10 10 20

48 8

Explanation :

Denoting Meliodas as M, Ban as B.

Testcase 1 :

M=5, B=3
Ban eates 3 chocolates of Meliodas.

M=2, B=3

Meliodas eats 2 chocolates of Ban.

M=2, B=1

Ban eates 1 chocolate of Meliodas.

M=1, B=1

Since they have the same no of candies, they stop quarreling.

Total candies left: 2

Testcase 2 :

M=10, B=10

Since both of them had the same candies to begin with, there was no point in fighting.

Total candies left: 20

Testcase 3 :

M=4, B=8

Meliodas eats 4 chocolates of Ban.

M=4, B=4

Since they have the same no of candies, they stop quarreling.

Total candies left: 8


RECTANGLE AND SQUARES
23 February 2024 18:29

Problem Statement : You are given a rectangular grid of dimension AXB. It is made
up of square tiles of dimension 1X1. You have to paint the entire grid. In one move
you are allowed to perform the following operation :
• Choose any positive integer C and paint any unpainted square of dimension CXC
inside the grid.
Find the minimum number of operations required to paint the entire grid.

Link : https://practice.geeksforgeeks.org/contest/job-a-thon-11-hiring-
challenge/problems
Your Task :

You don't have to read input or print anything. The task is to complete the function
minimumMoves() which takes two integers A,B,C as input parameters and returns the
minimum number of operations required to paint the entire grid.

Constraints :

1 ≤ AB ≤ 109

You might also like