Assessment Problems_VI Sem
Assessment Problems_VI Sem
Assessment Problems_VI Sem
Engineering
Assessment Problems: VIth Sem
Ques:1
Kanika and Harshita are playing a coin game. They are given n coins with values x1,
x2 …. xn where 'n' is always even. They take alternate terms. In each
turn, a player picks either the first coin or the last coin from the row and removes it from the
row. The value of coin is received by that player. Determine the max
imum value that Piyush can win with if he moves first. Both the players play optimally.
Input Format
Output Format
Print a single line with the maximum possible value that Kanika can win with.
Sample Input
4
1 2 3 4
Sample Output
6
Explanation
Kanika will pick the coin 4. Then Harshita can pick either 1 or 3. In both the cases Kanika picks
coin 2 and wins with a total of 6.
Ques:2
Take as input N, the size of a chess board. We are asked to place N number of Knights in it,
so that no knight can kill other.
a. Write a recursive function which returns the count of different distinct ways the knights
can be placed across the board. Print the value returned.
b.Write a recursive function which prints all valid configurations (void is the return type for
function).
Input Format
Constraints
None
Output Format
Display the number of ways a knight can be placed and print all the possible arrangements in
a space separated manner
Sample Input
2
Sample Output
{0-0} {0-1} {0-0} {1-0} {0-0} {1-1} {0-1} {1-0} {0-1} {1-1} {1-0}
{1-1}
Ques:3
You are given an N*M grid. Each cell (i,j) in the grid is either blocked, or empty. The rat can
move from position (i,j), down or right on the grid.
Initially rat is on the position (1,1). It wants to reach position (N,M). Find the rightmost path
through which, rat can reach this position. A path is rightmost, if the rat is at position (i,j), it
will always move to (i,j+1), if there exists a path from (i,j+1) to (N,M).
Input Format
First line contains 2 integers, N and M, denoting the rows and columns in the grid. Next N
line contains. M characters each. An 'X' in position (i,j) denotes that the cell is blocked and
ans 'O' denotes that the cell is empty.
Constraints
Output Format
If a solution exists: Print N lines, containing M integers each. A 1 at a position (i,j) denotes
that the (i,j) cell is covered in the path and a 0 denotes that the cell is not covered in the path.
th
Sample Input
5 4
OXOO
OOOX
OOXO
XOOO
XXOO
Sample Output
1 0 0 0
1 1 0 0
0 1 0 0
0 1 1 1
0 0 0 1
Ques:4
You are given a one dimensional array that may contain both positive and negative integers,
find the sum of contiguous subarray of numbers which has the largest sum. For example, if
the given array is {-2, -5, 6, -2, -3, 1, 5, -6}, then the maximum subarray sum is 7. NOTE:-
The first line consists of number of test cases T. Each test case consists of N followed by N
integers.
Constraints
Output Format
Ques:5
This year when Students visited DCE for DRONTECH 2019. He and GOPI started
discussing few problems on divide and conquer. Student asked GOPI that if you have 2
strings s1 and s2 can you find if they are equivalent. GOPI then asked the condition for being
equivalent to which student replied
Two strings a and b of equal length are called equivalent in one of the two cases:
Input Format
First line is number of test cases t Then follow two strings each of same length
Constraints
Output Format
print "YES" if they are "equivalent" and "NO" if they are not
Sample Input
3
ababa
baaba
ab
ba
abc
abc
Sample Output
NO
YES
YES
Explanation
Ques:6
Given n friends, each one can remain single or can be paired up with some other friend. Each
friend can be paired only once. Find out the total number of ways in which friends can remain
single or can be paired up.
Input Format
First line contains an integer t denoting the number of test cases. Next t lines contain an
integer n each.
Constraints
1<= n < 30
Output Format
Sample Input
1
3
Sample Output
4
Explanation
{1}, {2}, {3} : all single {1}, {2,3} : 2 and 3 paired but 1 is single. {1,2}, {3} : 1 and 2 are paired but
3 is single. {1,3}, {2} : 1 and 3 are paired but 2 is single. Note that {1,2} and {2,1} are considered
same.
Ques:7
Given a string containing duplicates, print all its distinct permutations such that there are no
duplicate permutations and all permutations are printed in a lexicographic order.
Input Format
The first and only line of the test case contains the input string.
Constraints
Output Format
Print all the distinct permutations in a lexicographic order such that each permutation is in a
new line. Note that there should not be any duplicate permutations.
Sample Input
ABA
Sample Output
AAB
ABA
BAA
Explanation
The possible permutations for the given string are { "AAB" , "AAB" , "ABA" , "BAA" } . We skip the
repeating "AAB" permutation and only print it in once. Also we print the final output in
lexicographical order.
Ques:8
Abhishek is a very passionate about sets. Lately, he is busy solving one of the problems on
sets. He has to find whether if the sum of any of the non-empty subsets of the set A is zero.
Input Format
The first line contains an integer T, which is the total number of test cases.
T test cases follow.
Each test case consists of two lines.
The first line consists of a single integer N, which is the number of elements present in the set
A.
The second line contains N space separated integers denoting the elements of the set A.
Constraints
1 ≤ T ≤10
1≤N≤4
-10^5 ≤ A[i] ≤ 10^5
Output Format
Sample Input
1
4
1 3 2 -3
Sample Output
Yes
Explanation
Ques:9
Given a floor of size n x m. Find the number of ways to tile the floor with tiles of size 1 x m .
A tile can either be placed horizontally or vertically.
Input Format
First line of input contains an integer T denoting the number of test cases. Then T test cases
follow.
The first line of each test case contains two integers N and M.
Constraints
Output Format
Print answer for every test case in a new line modulo 10^9+7.
Sample Input
2
2 3
4 4
Sample Output
1
2
Ques:10
Yash loves to play number games with his friend Harsh. One day they were playing a game
where one of them will speak out a positive number and the other have to tell the sum of its
factors. The first one to say it correctly wins. After a while they got bored and wanted to try
out a different game. Yash then suggested about trying the reverse. That is, given a positive
number 'S' , they have to find a number whose factors add up to 'S'. Realizing that this task is
tougher than the original task, Yash came to you for help. Luckily Yash owns a portable
programmable device and you have decided to burn a program to this device. Given the value
of 'S' as input to the program, it will output a number whose sum of factors equal to 'S' .
Input Format
There are several cases . Each case of input will consist of a positive integer 'S'<= 100000 .
The last case is followed by a value of 0 .
Constraints
Output Format
print the integer whose factors sum is equal to 'S'. Print the largest Integer whose factors sum
is 'S' . If no such number exists, output '-1' .
Sample Input
1
102
1000
0
Sample Output
1
101
-1