Beruflich Dokumente
Kultur Dokumente
Problem Description
Consider people calling out bids in different number bases at an auction. Find the
minimum bid assuming the following:
1. The bid numbers are in bases that make their respective values minimum.
Constraints
1. N <= 10
2. Maximum base = 36
Base 36: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O,
P, Q, R, S, T, U, V, W, X, Y, Z
Input Format
N different numbers in various bases, with numbers delimited by space
Output
The value in base 10 of the minimum bid.
Test Case
Explanation
Example 1
Input
11 12
Output
Explanation
The value of number represented by 11 is least in base 2 and that least value in
base 10 is 3. The least value of the representation 12 is in base 3 and is equal to
5. Since 3 < 5, 3 is the lowest bid and is the output.
Example 2
Input
1Z A L0 17
Output
10
Explanation
------------------------------------------------------
Prime Fibonnaci
Problem Description
Given two numbers n1 and n2
2. Make all possible unique combinations of numbers from the prime numbers list you
found in step 1.
4. Find smallest (a) and largest (b) number from the 2nd generated list, also count
of this list.
5. Consider smallest and largest number as the 1st and 2nd number to generate
Fibonacci series respectively till the count (number of primes in the 2nd list).
Constraints
2 <= n1, n2 <= 100
n2 - n1 >= 35
Input Format
One line containing two space separated integers n1 and n2.
Output
Last number of a generated Fibonacci series.
Test Case
Explanation
Example 1
Input
2 40
Output
13158006689
Explanation
1st prime list = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
Combination of all the primes = [23, 25, 27, 211, 213, 217, 219, 223, 229, 231,
237, 32, 35, 37, 311, 313, 317, 319, 323, 329, 331, 337, 52, 53, 57, 511, 513, 517,
519, 523, 529, 531, 537, 72, 73, 75, 711, 713, 717, 719, 723, 729, 731, 737, 112,
113, 115, 117, 1113, 1117, 1119, 1123, 1129, 1131, 1137, 132, 133, 135, 137, 1311,
1317, 1319, 1323, 1329, 1331, 1337, 172, 173, 175, 177, 1711, 1713, 1719, 1723,
1729, 1731, 1737, 192, 193, 195, 197, 1911, 1913, 1917, 1923, 1929, 1931, 1937,
232, 233, 235, 237, 2311, 2313, 2317, 2319, 2329, 2331, 2337, 292, 293, 295, 297,
2911, 2913, 2917, 2919, 2923, 2931, 2937, 312, 315, 317, 3111, 3113, 3117, 3119,
3123, 3129, 3137, 372, 373, 375, 377, 3711, 3713, 3717, 3719, 3723, 3729, 3731]
2nd prime list=[193, 3137, 197, 2311, 3719, 73, 137, 331, 523, 1931, 719, 337, 211,
23, 1117, 223, 1123, 229, 37, 293, 2917, 1319, 1129, 233, 173, 3119, 113, 53, 373,
311, 313, 1913, 1723, 317]
smallest (a) = 23
Therefore, the last number of a Fibonacci series i.e. 34th Fibonacci number in the
series that has 23 and 3719 as the first 2 numbers is 13158006689
Example 2
Input
30 70
Output
2027041
Explanation
1st prime list=[31, 37, 41, 43, 47, 53, 59, 61, 67]
2nd prime list generated form combination of 1st prime list = [3137, 5953, 5347,
6761, 3761, 4337, 6737, 6131, 3767, 4759, 4153, 3167, 4159, 6143]
Therefore, the last number of a Fibonacci series i.e. 14th Fibonacci number in the
series that has 3137 and 6761 as the first 2 numbers is 2027041
-----------------------------------------------------------------------
Balancing Stars
Problem Description
CODU loves to play with string of brackets.
However if string doesn't satisfies above conditions then print No and number of
balanced pair in string as an output.
Constraints
4 <= String length <= 1000
Input Format
The first and only line of input contains a string of characters(a-z,A-Z),
numbers(0-9), brackets( '{', '[', '(', ')', ']', '}' ) and stars(*).
Output
Print space separated "Yes" (without quotes) and number of balanced pair if string
is good. Else print "No" (without quotes) and number of balanced pair.
Test Case
Explanation
Example 1
Input
{**}
Output
Yes 1
Explanation
Here string contains one balanced pair {} and between this pair of bracket there
are 2 stars present so the output is Yes with the count of balanced pair as 1.
Example 2
Input
{**(**{**[**]})}
Output
Yes 4
Explanation
String has balanced brackets and also satisfies 2nd condition. So the output is Yes
with count of balanced pair which is 4.
Example 3
Input
**}xasd[**]sda231
Output
No 1
Explanation
In this case string is not balanced. So the output is No with the count of balanced
pair as 1.
---------------------------------------------------------------------------
King Placement
Problem Description
This is a typical chess game where your opponent first places random number of
Knights, Rooks, Bishop and Queens on an N*N chess board and then you have to place
your king safely on chess board such that it should not be under attack by any
piece.
Note: if you don't know how to play chess and how chess pieces moves, please refer
below link (you can concentrate only on how the above mentioned pieces moves).
https://www.instructables.com/id/Playing-Chess/
Constraints
2<=N<=50
0<=K+R+B+Q <=N*N
0<=i, j <=N-1
Input Format
First line provides an integer N
Next line contains K, no. of Knights. Next K lines provide 2 space separated
integers denoting the rank and the file of the Knights (i,j)
Next line contains R, no. of Rooks. Next R lines provide 2 space separated integers
denoting the rank and the file of the Rooks (i,j)
Next line contains B, no. of Bishops. Next B lines provide 2 space separated
integers denoting the rank and the file of the Bishops (i,j)
Next line contains Q, no. of Queens. Next Q lines provide 2 space separated
integers denoting the rank and the file of the Queens (i,j)
Output
Number of squares where King can be placed safely.
Test Case
Explanation
Example 1
Input
0 0
1 1
2 2
3 3
Output
Explanation
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@1aefe2ea:image1.png
The image shows the arrangement of the pieces. After the placement of all the
Pieces as per the input chess board looks like the image above,
You can place King in 2 places safely. i.e., (0,1) and (1,0)
Example 2
Input
2 6
3 2
5 6
7 7
4
2 2
4 6
6 4
7 5
0 4
1 1
1 6
5 1
3 5
6 0
Output
Explanation
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@1aefe2ea:image2.png
--------------------------------------------------------------------------------
The PMO hands over the list of political parties invited to the meeting. To
simplify things, let us assume that the parties are numbered 1,2,�N. The PMO also
hands over which of the pairs of parties that are friendly, and must be seated next
to each other and the parties that are inimical, who must not be seated adjacent to
each other. Given this information, find a seating arrangement for the meeting in
the circular table.
As the table is circular, we may assume that position 1 is occupied by party 1. The
output is a sequence of N party numbers starting from 1, which meets the criteria.
If there are multiple sequences that meet the criteria, the sequence that is the
lowest in lexicographic sequence is to be printed. If a possible seating
arrangement does not exist, the output must be -1.
Constraints
N <= 100
Input Format
First line contains N, the number of political parties
The next line contains a pair of space separated integers a b indicating the number
of pairs of friendly parties and number of pairs of inimical parties
Each of the next a lines contains a pair space separated integers u v where party u
is friendly with party v
Each of the next b lines contains a pair of space separated numbers x y where party
x is inimical with party y.
Output
If the seating arrangement is possible, the lexicographically smallest sequence of
N integers in order of the seating arrangement, starting with 1. These should be
space separated
If not possible, -1
Test Case
Explanation
Example 1
Input
3 2
1 5
3 4
1 6
2 3
2 4
Output
1 5 2 7 3 4 6
Explanation:
There are 7 political parties. There are 3 pairs of friendly political parties.
Party2 and Party 3 can not be seated together and Party 2 and 4 can not be seated
together. The above arrangement satisfies all the given constraints.
Example 2
Input
5
2 2
5 1
2 4
2 3
4 2
Output
-1
Explanation:
The conditions are inconsistent: 2, 4 should be seated together but 4, 2 should not
be. Hence no seating arrangement is possible.
---------------------------------------------------------------------------
Hermoine Number
Problem Description
Voldemort is finally dead. Hermoine is bored and has now developed some interest in
mathematics, so she keeps challenging her friends. Harry is now one of the victims
to those hard problems and needs your help to solve this puzzle.
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@74977d0c:image1.png
Since H can be large, you need to print the result modulo MOD = 1000000007
Constraints
N <= 10^5
Input Format
First line provides an integer N denoting number of elements in Array A
Third Line provides an integer denoting Query (q) corresponding the problem
statement
Next q lines contain two numbers l, r denoting the values mentioned above in the
statement
Output
q lines containing the value of H mod 1000000007
Test Case
Explanation
Example 1
Input
5
1 2 3 4 5
2 2
2 4
Output
82944
Example 2
Input
10
77883 48760 68269 31574 57351 20528 45398 54148 37399 31382
10
5 9
2 8
2 9
6 6
1 3
1 9
7 8
6 10
2 7
1 2
Output
667891964
31641898
769678014
29992112
654285930
776096678
444042335
886182048
728170986
------------------------------------------------------------