Lab 0
Lab 0
Question-1
Consider a set of n number of dice arranged in two rows as shown in the figure below, where both top and bottom rows have
the same number of dice. The displayed numbers of the corresponding dice in the two rows may or may not match. For
example in the first part of the figure, the top row displays the numbers 2, 1, 2, 4, 2, 2, whereas the bottom row displays the
numbers 5, 2, 6, 2, 3, 2. Our goal is to exchange the dice in the same column(s) so that the displayed numbers either in the
top or the bottom row become the same, and this needs to be performed with minimum number of exchanges. In the bottom
part of the figure below, exchange of dice are performed in 2nd and fourth column, which results in the top row displaying
the same number (which is 2).
Your code should take the numbers in the top and bottom rows as two integer arrays, and return the minimum number of
exchanges required as an integer number. If there is no such exchange possible to make the two rows equal, then return -1.
Ex1:
Input: top = [2,1,2,4,2,2], bottom = [5,2,6,2,3,2]
Output: 2
Ex2:
Question-2
Suppose that you are given a string consisting of lowercase english alphabets and parentheses. The parentheses are balanced,
that is there are matched number of opening and closing braces. Your task is to reverse the strings in each pair of matching
parentheses, starting from the innermost one. The final result should not have any parentheses.
Ex1:
1
Input string: "(algorithm)"
Output string: mhtirogla
Ex2:
Input string: "(u(copy)i)"
Output string: icopyu
Ex3:
Input string: "(re(mp(li))oc)"
Output string: compiler
Question-3
Storing large integer numbers like 9123456789123456789123456789123 is difficult, which can be efficiently performed by the
use of linked lists, where each node will represent each digit of the number (the least significant digit will be at the beginning
of the list). Your task is to take two large integer numbers as input in the form of strings, store these in two separate linked
lists, perform addition of these numbers, and display the final result.
Ex1:
Enter the first number: 55987598712265477765
Enter the second number: 17709860334275119679
The sum is: 73697459046540597444