You are on page 1of 2

Assignment 4

1. You are given a m x n chessboard. Assign color to it using a m x n matrix (2d


array). Then try using vector of vectors.
Eg : m = 3, n = 5
Color[][] = {
{1, 0, 1, 0, 1},
{0, 1, 0, 1, 0},
{1, 0, 1, 0, 1}
}

2. You are given a n x n snake and ladders game board. Assign number to it using
n x n matrix (2d array). Then try using vector of vectors.
Eg: n = 4
Number[][] = {
{16, 15, 14, 13},
{9, 10, 11, 12},
{8, 7, 6, 5},
{1, 2, 3, 4}
}

3. Given a and b, find their gcd using recursion.


4. Catalan numbers are defined as :-
Catalan(n) = 1 ; n <= 1
Σ Catalan(i) * Catalan(n-1-i) {i from 0 to n-1}; n >= 2
Eg: Catalan(4) = Catalan(0)*Catalan(3) + Catalan(1)*Catalan(2) +
Catalan(2)*Catalan(1) + Catalan(3)*Catalan(0)
= 1*5 + 1*2 + 2*1 + 5*1
= 14
Given n, find Catalan(n) using recursion (and iteration).

5. Given n, find the sum of digits of n using recursion.


6. Given a vector V of n elements, display all subsets of it.
Eg: n = 3, V = {1, 2, 5}
Subsets = {}, {1}, {2}, {5}, {1, 2}, {1, 5}, {2, 5}, {1, 2, 5}

7. Given two strings s and t, report whether s is a subsequence of t or not. Use


recursion.
Eg: 1) s = “aks”, t = “rakesh”
YES
2) s = “zzz”, t = “xyzzuv”
NO

8. Given a vector V of n elements, display all k-subsets of it.


Eg: V = {1, 2, 5, 3}. K = 3
K-Subsets = {1, 2, 5}, {1, 2, 3}, {2, 5, 3}, {1, 5, 3}

9. Given a number n, generate all n c­ haracter passwords. Each character of the


password can either be a lowercase character or a digit. Also, every password
must contain at least one lowercase character and a digit.

10. Given a number n, generate all distinct ways to write n as the sum of positive
integers.
Eg: n = 4,
Ways = 4, 3 + 1, 2 + 2, 2 + 1 + 1 and 1 + 1 + 1 + 1
11. You are given Q queries. Take an empty vector and based on type of query, do
the following operations:-
1 x : Append x to the end of the vector
2 : Sort the vector in ascending order
3 : Sort the vector in descending order
4 : Print the size of the vector followed by ‘\n’
5 : Reverse the vector
6 : Display all the elements of the vector separated by space followed by ‘\n’.

Eg: Q=5
Queries = 4
16
1 -8
1 28
3
5
6
Output = 0
-8 6 28
12. Solve https://projecteuler.net/problem=7
13. Solve https://atcoder.jp/contests/abc168/tasks/abc168_c
14. Solve https://atcoder.jp/contests/abc164/tasks/abc164_c
15. Solve https://codeforces.com/contest/1537/problem/A

You might also like