Week - 7th , Assignment - 1st

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

DSA With Coding Army

Assignment -1st Week – 7th Date : 07/07/2024


1. Write a program to calculate the sum of odd numbers between a and b (both inclusive) using
recursion.
2. Calculate the number of ways in which a person can climb n stairs if he can take
exactly 1, 2 or 3 steps at each level.
3. Given a positive integer, return true if it is a power of 2.
4. Print all the elements of an array in reverse order.
5. Print index of a given element in an array.
6. If not present, print -1. A function countAndSay is defined as
countAndSay(1) = “1”
countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1),
which is then converted into a different digit string.
So, if sample input is n = 4,
countAndSay(1) = 1
countAndSay(2) = “one 1” => 11
countAndSay(3) = “two 1” => 21
countAndSay(4) = “one 2 one 1” => 1211
7. Given an array of integers, print a sum triangle using recursion from it such that the
first level has all array elements. After that, at each level the number of elements is
one less than the previous level and elements at the level will be the sum of
consecutive two elements in the previous level. So, if sample input is [5, 4, 3, 2, 1],
sample output will be:
[5, 4, 3, 2, 1]
[9, 7, 5, 3]
[16, 12, 8]
[28, 20]
[48]
8. Write a recursive function to reverse a number.
9. Avoid preceding 0s in the reversed number. Print all the increasing sequences of
length k from first n natural numbers.
10. Given an integer array containing unique numbers, return power set, containing all
the subsets of the set. [Leetcode 78]
11. Given an integer array which may contain duplicate numbers, return power set,
containing all the subsets of the set. [Leetcode 90]
12. Given a string, find the length of the longest common substring from two given
strings.
13. Program to find the factorial of a given number.
14. Program to convert a decimal number to binary

Note:- Please try to invest time doing the assignments which are necessary to build a
strongfoundation. Do not directly Copy Paste using Google or ChatGPT. Please use
your brain 😃.

You might also like