CodeVita 2016 Round 2
CodeVita 2016 Round 2
CodeVita 2016 Round 2
Mate in two
Decrypt the Crypt
Crack the Password
Verify JSON Object Validity
The Mystery of Sky
Collecting Candies
the Vita Sum
Game of Marbles
Background
For the purpose of this problem, only consider first of the six fields of FEN. Before we
describe the problem, let us look at how FEN maps to a board position. The following 5
images show board positions and its corresponding FEN representation.
Figure 1.
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
Let's say, White plays e4. Then the board position looks like shown below
Figure 2.
rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR
3. rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR
4. rnbqkbnr/pppp1ppp/8/4p3/4PP2/8/PPPP2PP/RNBQKBNR
5. rnbqkbnr/pppp1ppp/8/8/4Pp2/8/PPPP2PP/RNBQKBNR
Wikipedia describes first field of FEN format as follows
Piece placement (from white's perspective). Each rank is described, starting with rank 8
and ending with rank 1; within each rank, the contents of each square are described from
file "a" through file "h". Following the Standard Algebraic Notation (SAN), each piece is
identified by a single letter taken from the standard English names (pawn = "P", knight =
"N", bishop = "B", rook = "R", queen = "Q" and king = "K").[1] White pieces are designated
using upper-case letters ("PNBRQK") while black pieces use lowercase ("pnbrqk"). Empty
squares are noted using digits 1 through 8 (the number of empty squares), and "/"
separates ranks
Statement
Given a board position in FEN format, your task is to find out all move(s) that lead to a
forced mate. White to play and win in 2 moves.
Input Format:
Output Format:
a. A string in format by "< move format >-< move format >-< move
format >", where first move is white move, second is black move and third
is again a white move
b. Where < move format > is move represented in format
"fromSquaretoSquare"
2. See Example section for better understanding of output format
Constraints:
1
r1b2rk1/1p4pR/p2pppn1/6q1/3NP1P1/2N2P2/PPP4Q/1K5R h7g7-g8g7-h2h7
2
5r1k/p4p1p/5P1N/1p1p4/2pP3P/8/PP4RK/8 g2g8-f8g8-h6f7
Explanation:
Board position for sample input 1: Mate enforcing moves for input 1:
Figure 6.
Figure 7.
Board position for sample input
Mate enforcing moves for input 2:
2:
Figure 9.
Figure 8.
Walter uses multiple applications at his workplace. He was assigned a unique password of
variable lengths for each application (maximum length being 10). The only common factor
among them was that all the passwords were a combination of 10 distinct characters.
Walter created an algorithm to encrypt these passwords and wrote the codes on his desk
to avoid a situation in which he would not be able to recollect a password.
Decrypt the encrypted password that has been created by Walter using the above
algorithm to compute the actual password!
Input Format:
1. First line contains the encoded password as it should be according to
Walter's algorithm
2. Second line contains 10 unique characters
Output Format:
Obtained password by reverting the algorithm. Print -1 if there is any error in the inputs.
Constraints:
1. Second line of input MUST contain 10 DISTINCT characters.
2. Encoded password should be in format
< value_of_C >|| < contents_of_array_B >
1 0|1|2|43|14|5|6|7|308|29||0149
@@Z$$
*Acf$Zd&T@
2 0|1|2|43|14|5|6|7|308|29||0149
-1
*Acf$Zd&T
NOTE: - The following are the steps used to encrypt the password. Your task is to reverse
the logic and decrypt the encrypted string provided as input, and get back the clear-text
password.
1. Consider input characters and its position
Password :@@Z$$
Numeric value:9 9 5 4 4
4.
(Note: Remember leftmost value (Say A) = 9)
5. Starting from the left most position, add each digit to the digit on its right.
Add the last digit with the first digit in the sequence
Format:0|1|2|3|4|5|6|7|8|9
10. Now, each number in this format is pre-appended with the positions of the
occurrence of the respective number in the output obtained in selective
subtraction step of Step 4.
Encrypted password:0|1|2|43|14|5|6|7|038|29
11.
(Note: Say C = 0|1|2|43|14|5|6|7|038|29)
12. The final encrypted password will be of the following format to account for
the calculations performed in generating the encrypted password
Atul does lots of online transactions and has accounts in multiple banks, but to remember
his passwords he created his own encryption technique and wrote down the enciphered
passwords in a notepad. But he finds it very time consuming to decipher those passwords
so he has asked for your help to develop a program to do the task quickly.
Your are provided with the eMat (encrypted matrix) or the matrix B, your task is to find all
possible passwords and print them.
Example:
Let the password be "passwords" as it has 9 characters , the most appropriate matrix will
be a 3X3 matrix, hence the matrix will be
After Step 1:
After step 2:
After step 3:
-0.783783783780.18918918919 0.70270270270
-0.118503118500.07900207900 0.09563409563
0.87733887734 -0.25155925156 -0.72557172557
Input Format:
1. First line contains integer N, which is the dimension of square matrix eMat
2. Next N lines contain N space separated values (11-digit precision after
decimal point) representing the eMat.
Output Format:
In a single line print the password, if multiple password values are possible print them
separated by space, sorted by ascending order of their lengths.
Constraints:
1. When eMat is converted to Matrix A, round off the numbers in the matrix A
to its nearest integer value to recover the alphabets in the password
3
1 -0.78378378378 0.18918918919 passwords
0.70270270270
-0.11850311850 0.07900207900
0.09563409563
0.87733887734 -0.25155925156 -
0.72557172557
2
2 0.06666666667 -0.06666666667 pas pass
-0.00350877193 0.05614035088
A JSON object is a key-value pair data structure that is enclosed within { }. A sample JSON
object would look like
{
"key1":"value1",
"key2":"value2",
"key3": {
"key4":"value4",
"key5":"value5"}
"key6":"value6",
"key7":[
{
"key8":"value8"
}]
}
Given a JSON object, ignore the literal values of the object and check whether the
distinguishing characters and notation of the object are valid to determine if the JSON
object is valid or not.
Note:
Input Format:
Output Format:
Constraints:
1. A JSON object should start with '{' and ends with a '}'.
2. The key and value should be separated by a ':'.
3. A ',' suggests an additional JSON property.
4. An array only consists of JSON objects. It cannot contain a "key":"value" pair
by itself.
Example 1:
Input
{:[{},{}]}
Output
1
Explanation
{
"Key": [{
"Key": "Value"
}, {
"Key": "Value"
}]
}
Pattern is following all constraints hence prints 1
Example 2:
Input
{:{[]},{}}
Output
-1
Explanation
Convert this pattern in a JSON Object
{
"Key": {
[
"Key": "Value"
]
},
{
"Key": "Value"
}
}
Constraint 4 "An array only consists of JSON objects. It cannot contain a "key":"value" pair
by itself." not followed here, so it's a invalid pattern, hence prints -1
Stark is a 10 year old kid and he loves stars. So, he decided every day he will capture a
picture of a sky. After doing this for many days he found very interesting observations.
Every day the total number of stars in the sky is same as days completed for a calendar
year. He noticed, on Saturday's and Sunday's that there are no stars in the sky. Stark's
camera does not have wide angle capture feature so he could only capture maximum of
50 stars at a time. So, he assumed that there are only 50 stars in the sky that day. Also, the
camera discharges every 4th day and he is not be able to click any picture that day. So let's
say, if the first day of calendar (01/01/0001) starts on a Monday then on Thursday he can't
click any pictures. Then resuming on Friday he can take pictures until Sunday, but can't
take picture on Monday, followed by downtime on Friday, then Tuesday, then Saturday
etc. When the camera discharges he considers 0 stars that day.
You are his programmer friend and want to help him. You need to write a code which will
tell him on a particular date how many stars Stark's camera was able to click.
You can assume Stark has an ancient camera and your first input will be the day for date
(01/01/0001) and then followed by any date on which Stark wants to find out the number
of stars in the sky.
Input Format:
Every line of input will contain a Day at date 01/01/0001 in dd/mm/yyyy format followed
by a Date in the same format (on which we have to count the stars)
Output Format:
For valid Input
Count of the number of stars in the sky on the given date
1 Monday
Invalid Date
30/02/1990
2
Thursday Invalid Day
Its 24th day of the year and neither is
3 Wednesday
24 Saturday/Sunday nor has the camera discharged
24/01/2056
on this day.
Krishna loves candies a lot, so whenever he gets them, he stores them so that he can eat
them later whenever he wants to.
At a time he can pick up any two boxes for transferring and if both the boxes say contain X
and Y number of candies respectively, then it takes him exactly X+Y seconds of time. As he
is to eager to collect all of them he has approached you to tell him the minimum time in
which all the candies can be collected.
Input Format:
Output Format:
Print minimum time required, in seconds, for each of the test case. Print each output on a
new line.
Constraints:
1. 1 ≤T≤10
2. 1 ≤N≤ 10000
3. 1 ≤ [Candies in each box] ≤ 100009
Tom the cat is brushing up his Math skills. He has a bag containing N balls of different
colors. Now Tom can randomly pick any even number of balls from the bag. Tom wants to
find out the sum of all such combinations of balls that he can pull out from the bag. He can
pull out at max K balls in one pick.
Input Format:
The output is the sum of all the combinations of balls he can pull out modulo 10^9+7 i.e.
(1000000007)
Constraints:
1. 0<=N,k<=10^14
2. N >= k
Darrell and Sally are two best friends. They had a large collection of marbles. They devised
a game with it to play in their free time which will also help them to improve their math.
One of them will have to select a certain number of marbles and give a hint to find the
number. The other will have to guess the first number that matches the given criteria and
vice versa.
Your task is to act as a judge for this game. When the player finds the answer, you will
have to verify the answer. If answer is right, add 10 points to that player. If the player
passes the question, you will have to give the right answer (no change in points in this
case). You should also announce the winner at the end of the game.
When the marbles are put into a group of x1, x2, x3,...(where x1, x2, x3 can be any number
from 1 to 100), it falls into a perfect group.(No marble is left without a group).
Example: - When Darrell says the number falls into a perfect set when she groups them
into sets of 3 and 5, the answer could be 15 or 30 and so on. Since the first number that
matches the criteria is 15, 15 will be the answer.(Explanation: when 15 marbles is put into
groups of 3, We will get 5 sets of 3 marbles each and when it is put into groups of 5, we
will get 3 sets of 5 marbles each. For 16 marbles, we will get 5 sets of 3 marbles each and
one marble will be left without a proper group. So 16 cannot be the answer)
NOTE: - Please have a look at Sample Input and Output before you read the Input and
Output specification
Input Format:
3. Third line must be an Answer Giving line which is the answer to the
precedingQuestion Posing line. The format of the Answer Giving line is as follows :
a. answer above can only be an integer number OR it will be a constant
string "PASS"
b. An integer number represents the value of the answer given by the
Player
c. If the Player does not know the answer she will "PASS" the question
4. Fourth line onwards, if they exist, will be alternating series of Question
Posing and Answer Giving lines in case of Valid inputs
5. In case of any Invalid Question Posing line, requisite output must be printed
for all previous Valid Question posing line(s).
6. Processing should stop at Invalid input line after printing required message
in output. See output specifications and sample test cases to understand points 5)
and 6) better
Output Format:
1. First line of output must reiterate the question in the following
format < Player Name >'s question is : X 1,X2,X3...,Xn>
7. Second line should be an evaluation of the first Answer Giving line of the
input. The evaluation message will either be { Correct Answer or Wrong Answer}
8. If the answer
. is correct, output, : 10points
a. is wrong, output, : 0points
b. is "PASS"-ed by the player,
i.output "Question is PASSed"
ii.output "Answer is: " where correct_answer_value is the correct
answer for the question passed by the player.
iii.output ": 0points"
c. Overall points collected by players have to be tracked and output
when all valid inputs are processed
9. If all inputs are valid, after processing all the inputs, the final output should
be comprised of the following 4 lines
. Output "Total Points:" on fourth last line
a. Output ": points" on 3rd last line, where Player1 is the one who first
posed the question
b. Output ": points" on 2nd last line, where Player2 is the one who first
answered the question
c. If there is a winner Output "Game Result: is winner" or "Game
Result: Draw"
10. Print "Invalid Input" in case of invalid input or failing constraint
Constraints:
0. 0 < N <= 10
1. Player Names are Case-sensitive
2. Number of inputs in a Question posing line will be 2<=n<=7 and
1<=Xn<=100
3. <X1 ,X2,X3...,Xn> can only be integers
2
3 Darrell Invalid Input
A Sally 15
4
Sally's question is: 3,5
Sally 3,5
Correct Answer
4 A Darrell 15
Darrell: 10points
Darrell
Invalid Input
A Sally 15