codevita
codevita
It has a beetle
on it, and some sweet honey spots at various locations on the surface of
the cube. The beetle starts at a point on the surface of the cube, and
goes to the honey spots in order along the surface of the cube.
Problem Description
A solid cube of 10 cm x 10cm x 10 cm rests on the ground. It has a beetle
on it, and some sweet honey spots at various locations on the surface of
the cube. The beetle starts at a point on the surface of the cube, and
goes to the honey spots in order along the surface of the cube.
1. If it goes from a point to another point on the same face (say X to Y),
it goes in an arc of a circle that subtends an angle of 60 degrees at the
centre of the circle
Input
The first line gives an integer N, the total number of points (including the
starting point) the beetle visits
Output
One line with a number giving the total distance travelled by the beetle
accurate to two decimal places. Even if the distance travelled is an
integer, the output should have two decimal places.
Constraints
None of the points the beetle visits is on the bottom face (z=0) or on any
of the edges of the cube (the lines where two faces meet)
2<=N<=10
Difficulty Level
Complex
Examples
Example 1
Input
1,1,10,2,1,10,0,1,9
Output
4.05
Explanation
There are three points visited by the beetle (N=3). The beetle starts on
the top face of the cube (z=10) at point (1,1,10) and goes to another point
on the same face (2,1,10). Though the straight line distance is 1, it
travels on the arc of a circle subtending an angle of 60 degrees at the
centre of the circle, and hence travels (2*pi)/6 or 1.05 (note that it rounds
the distance at each leg of the journey). It then travels from (2,1,10) on
the face z=10 to (0,1,9) on the face x=0 along the surface of the cube.
This is a distance of 3. The total distance travelled is 1.05+3=4.05. The
output is 4.05
Example 2
Input
3
1,1,10,2,1,10,0,5,9
Output
6.05
Explanation
There are three points visited by the beetle (N=3). The beetle starts on
the top face of the cube (z=10) at point (1,1,10) and goes to another point
on the same face (2,1,10). As before. This distance is 1.05. It then
travels from (2,1,10) on the face z=10 to (0,5,9) on the face x=0 along
the surface of the cube. The shortest distance on the surface of the cube
between these points is 5. The total distance travelled is
1.05+5=6.05. The output is 6.05.
The parcel section of the Head Post Office is in a mess. The parcels that
need to be loaded to the vans have been lined up in a row in an arbitrary
order of weights. The Head Post Master wants them to be sorted in the
increasing order of the weights of the parcels, with one exception. He
wants the heaviest (and presumably the most valuable) parcel kept
nearest his office.
Problem Description
The parcel section of the Head Post Office is in a mess. The parcels that
need to be loaded to the vans have been lined up in a row in an arbitrary
order of weights. The Head Post Master wants them to be sorted in the
increasing order of the weights of the parcels, with one exception. He
wants the heaviest (and presumably the most valuable) parcel kept
nearest his office.
You and your friend try to sort these boxes and you decide to sort them
by interchanging two boxes at a time. Such an interchange needs effort
equals to the product of the weights of the two boxes.
Input
The first line consists of two space separated positive integers giving the
number of boxes (N) and the position of the Head Post Master’s office
(k) where the heaviest box must be.
The second line consists of N space separated positive integers giving the
weights of the boxes. You may assume that no two weights are equal.
Output
The output is one line giving the total effort taken to get the boxes in
sorted order, and the heaviest in position k.
Constraints
N<=50
Difficulty Level
Complex
Examples
Example 1
Input
52
20 50 30 80 70
Output
3600
Explanation
There are 5 boxes (N=5) and the heaviest box must be in position 2
(k=2). If we look at the final order (sorted, with the heaviest at position
2), it should be 20 80 30 50 70. If we look at this, we notice that only the
50 and the 80 parcels need to be exchanged. As this takes effort of the
product of the weights, the effort is 4000.
50 80 30 20 70
20 80 30 80 70
Example 2
Input
63
30 20 40 80 70 60
Output
7600
Explanation
There are 6 parcels, and the heaviest should be at position 3. Hence the
final order needs to be 20 30 80 40 60 70. If we look at the initial
position, we see that 20 and 30 need to be exchanged (effort 600), 40 and
80 need to be exchanged (effort 3200) and 60 and 70 need to be
exchanged (effort 4200). Hence the total effort is
600+3200+4200=8000.
(600) 20 30 40 80 70 60
(3200) 20 30 80 40 70 60
(1200) 60 30 80 40 70 20
(1400) 60 30 80 40 20 70
(1200) 20 30 80 40 60 70
They have booked tickets for the city contingent for the same row, and
the size of the contingent (N) is smaller than the number of seats
booked(S).Unfortunately, there was rain the previous night and some of
the seats are still wet. Some of the contingent love Bowls so much and are
excited enough not to mind sitting on a wet chair. There are k of these.
However, others want to sit on a dry seat so that they can enjoy the
match more.
The contingent wants to minimize the distance between the first and last
person in the row so that they can still conduct Mexican Waves, and other
forms of support for their team.
There are M blocks of seats, starting with a dry block, with alternating wet
and dry blocks. The number of seats in each block is known.
Given S (the number of seats in the row), N (the size of the contingent),k
(the number of the contingent who are willing to sit in a wet seat), and the
distribution of wet and dry blocks, write a program to find the minimum
distance between the first and the last member of the contingent in the
row.
Input
The first line contains four comma separated numbers representing S, N, k
and M respectively.
Output
One integer representing the minimum distance between the first and last
member of the row. If it is impossible to seat all the members according
to their preferences,and with the unoccupied seat restriction, the result
should be 0.
Constraints
S,N,k < 1000, M < 30
Difficulty Level
Complex
Examples
Example 1
Input
100,50,5,6
3,10,30,5,30,22
Output
49
Explanation
S = 100, and there are 100 seats in the row. N=50, and there are 50
members in the contingent. k=5, and 5 people (out of the 50) do not mind
sitting on wet seats. M=6, and there are 6 blocks of seats. The number of
seats in each block is 3,10,30,5,30 and 22, with the first block of 3 seats
being dry, the next 10 being wet and so on.
Example 2
Input
100,50,5,8
3,7,10,10,20,10,20,20
Output
64
Explanation
S = 100, and there are 100 seats in the row. N=50, and there are 50
members in the contingent. k=5, and 5 people (out of the 50) do not mind
sitting on wet seats. M=8, and there are 8 blocks of seats.
One possible positioning is to have a set of 10 people sit in the dry block
11 – 20, the 5 people who will accept wet seats in seats 21 – 25 (in
the wet block 21 – 30), another 20 people in the dry block 31 – 50,
leave the wet block 51-60 empty, and seat the remaining 15 people in
seats 61 – 75 (in the dry block 61-80. There is a block of 5 unoccupied
seats (26-30) between the first person and the last person. As this is not
more than 15, this is acceptable. The distance from the last allocated seat
(75) and the first allocated seat (11) is 64. This is the result.
A cylindrical water cistern was built in an apartment complex in
Aquatown. The bottom rests on concrete and is not accessible. It has a
height h and a radius r.
Problem Description
A cylindrical water cistern was built in an apartment complex in
Aquatown.
The bottom rests on concrete and is not accessible. It has a height h and a
radius r,
For a point C on the curved surface, the nearest point D on the top is
determined, and the distance CD is taken as t. The angle p (in degrees)
subtended at the centre of the circle E by the arc BD is measured (in a
counterclockwise manner). The coordinates of C are taken as the pair
(t,p), with t being greater than 0 and less than h, and with p being
between 0 and 359 (inclusive).
For a point on the top surface, F, the distance to the centre E is taken (a),
and the counterclockwise angle (in degrees) between EF and EB is taken.
The coordinates of the point F are then taken as (-a,q). The value of a is
between 0 and r, and the value of q is between 0 and 359.
All coordinates are integers, and if the point is on the top surface of the
cylinder, the first coordinate is negative, and if it is on the curved surface
of the cylinder, the first coordinate is positive.
From its staring point A, the bug needs to go to its destination, which is a
point (like C or F) either on the curved surface or the top surface. The
coordinates of the destination are given. The bug would like to go by the
shortest path to its destination.
The goal is to determine the length of the shortest path the bug can take.
Input
The first line has three comma separated positive integers giving r (the
radius), h (the height of the cylinder) and s (the distance from the top of
the starting point of the bug)
The next line has two comma separated integers (d and g) giving the
coordinates of the destination. If the first integer (d) is negative, it is on
top surface of the cylinder, and else it is on the curved surface of the
cylinder
Output
The output is a single integer giving the shortest distance that the bug
can travel. The computed distance must be rounded to the nearest
integer
Constraints
40<s<=h<10000
r<100
0<=g<=359
If d is negative, d > -r
If d is positive, d < h
Difficulty Level
Complex
Examples
Example 1
Input
100,500,200
200,180
Output
314
Explanation
The value of r is 100, and h is 500. The distance of the bug from the top
surface is 200.
Example 2
Input
100,500,200
-50,180
Output
350
Explanation
The value of r is 100, and h is 500. The distance of the bug from the top
surface is 200.
The coordinates of the destination are (-50,180). As the first coordinate is
negative (-50), the point is on the top surface of the cylinder (like point F),
and EF is 50. As the second coordinate is 180, BEF is a straight line. The
distance travelled is AB + BE + EF = 200 + 100 + 50=350. This is the
output.
n the theory of numbers, square free numbers have a special place. A
square free number is one that is not divisible by a perfect square (other
than 1).
Problem Description
In the theory of numbers, square free numbers have a special place. A
square free number is one that is not divisible by a perfect square (other
than 1). Thus 72 is divisible by 36 (a perfect square), and is not a square
free number, but 70 has factors 1, 2, 5, 7, 10, 14, 35 and 70. As none of
these are perfect squares (other than 1), 70 is a square free number.
For some algorithms, it is important to find out the square free numbers
that divide a number. Note that 1 is not considered a square free
number.
In this problem, you are asked to write a program to find the number of
square free numbers that divide a given number.
Input
The only line of the input is a single integer N which is divisible by no
prime number larger than 19
Output
One line containing an integer that gives the number of square free
numbers (not including 1)
Constraints
N < 10^9
Difficulty Level
Simple
Input
20
Output
Explanation
N=20
1, 2, 4, 5, 10, 20
Example 2
Input
72
Output
Explanation
long sum = 0;
int N = sc.nextInt();
sum += Integer.parseInt(str);
logger.debug(sum%100);
Given N number of x's, perform logic equivalent of the above Java code
and print the output
Input
First line contains an integer N
Output
Number that is the output of the given code by taking inputs as specified
above
Constraints
1<=N<=10^7
0<=x<=10^18
Difficulty Level
Simple
Time Limit (secs)
1
Examples
Example 1
Input
8674
Output
64
Example 2
Input
123
Output
14
Given a n*n Array matrix (A) with A[0][0] element as the starting point
and any one element as the destination.
Problem Description
Given a n*n Array matrix (A) with A[0][0] element as the starting point
and any one element as the destination. Find the destination and print the
route map.
Rules:
1. Array Matrix with n*n elements such that n >=2 and n<=10.
2. Starting point A[0][0] value will be 'A'.
3. Destination value will be 'D'
4. There will be always 1 continuous route which can be straight or
diagonal.
5. There are 4 types of hurdles and corresponding values :
a. Stone denoted by 'S'
b. Wall denoted by 'L'
c. Water denoted by 'W'
d. Thorn denoted by 'T'
6. Music provides mind peace. Which will be denoted by 'M'. It is not a
hurdle.
7. The value of route will be 'R'.
Input
First Line contains dimension N of Matrix A.
Output
At every Step print the surrounded hurdles in ascending order of values.
i.e. for every 'R' print the surrounding hurdles.
If there are no hurdled around step in the route, print 'NO HURDLES' for
that step.
Constraints
2 <= N <= 20
Difficulty Level
Simple
Examples
Example 1
Input
4
ASLD
TRWR
RMSR
WRRM
Output:
LSSTW
TW
SW
SW
LSW
DESTINATION
Example 2
Input:
ASLWM
RSLDT
MRTRM
TLRMS
SLSWT
Output:
SS
LLSTT
LLSTW
LSTT
DESTINATION4
BoardGamesMarks: 30
Problem Description
Ankitha enjoys finding new games. One day, she found a grid with dimensions M*N
and decided to make up a special game to play on it. When Ankitha came up with
the idea for the new game, her friend Akhil joined her. She then decided to share
and explain the game to him.
Akhil is given a grid with dimensions M*N, where each cell contains either 0 or 1.
Additionally, he is provided with the coordinates of source and destination cells.You
can only move to places whose value is 0. Furthermore, he is given the move rule (x,
y) which helps in finding the location for the next move. From the given cell, you can
move in four directions (forward, back,right ,left), unless they are out of grid. The
rules for finding the next move from a current cell are given below.
For moving forward, add the move rule to the current cell.
For moving right, from current position add the move rule, rotate the path
90 degree clockwise,
For moving left, from current position add the move rule, rotate the path 90
degree anticlockwise direction,
For moving backward, from current position add the move rule, rotate the
path 180 degree in clock or anti clockwise.
The rules can be understood better from the following example. Let the current cell
be (1,1) and the move rule as (1,2)
Obeying the given move rule, find out minimum how many cells he need to travel in
order to reach the destination.
Constraints
4 <= M, N <= 50
Input
First line consist of two space separated integers M and N denoting the number of
rows and columns in the grid.
Next line consists of two space separeted integers denoting source cell.
Next line consists of two space separated integers denoting destination cell.
Last line consists of two space separated integer representing move rule.
Output
Print a single integer denoting the minimum moves required to reach the
destination.
Examples
Example 1
Input
66
010000
000001
010000
110001
000000
110010
10
53
12
Output
Explanation
Akhil needs to move from (1, 0) to (5, 3) and the given step for next move is (1, 2).
In order to minimise the number of moves, he follows the path (1,0) -> (2,2) -> (3,4)
->(5,3) where in total he made 3 moves. No other paths will give moves less than 3.
Hence print 3 as the output.
Example 2
input
66
000010
001001
010100
111000
100001
100110
00
44
02
Output
Explanation
Akhil needs to move from (0, 0) to (4, 4) and the given step for next move is (0, 2).
In order to minimise the number of moves, he follows the path (0,0) -> (0,2) -> (2,2)
-> (2,4) -> (4,4) where in total he made 4 moves. No other paths will give moves
less than 4. Hence print 4 as th output.
XFromYMarks: 30
Problem Description
Malaika is very fond of strings so whenever she gets some free time, she will keep
herself engaged in string based activities.
One day, she came across a question where she will be given two strings X & Y and
asked to form X from Y. The rules for forming the string are given below.
The string X should be formed with the concatenation of the sub strings of
Y. You can also select the sub strings from Y in reversed order.
The length of the sub strings selected from Y should be greater than or
equal to one.
Aim is to minimize the number of sub strings that are selected from Y and
concatenated to form X.
A term String Factor is defined which is calculated as (number of sub
strings selected from Y) * S + (number of sub strings selected from
reversed Y) * R, where S and R are given in the input.
You also have to minimize the String Factor while maintaining the minimum
number of sub strings.
Given two strings X and Y and two integers S and R, find the minimum String
Factor of the string X following above rules.
Constraints
1 <= lengths of X,Y <= 10^4
Input
First line consists of string X.
Output
Form the string X from string Y following the above rules and print the String Factor
of X. Print "Impossible" if X can't be formed from Y.
Examples
Example 1
Input
niveditha
lavekdahnita
35
Output
17
Explanation
For forming the string niveditha from lavekdahnita, select sub strings ni from Y, ve
from Y, d from Y, it from Y, ha from reversed Y. No other selections can give less than
five sub strings.
String Factor = (number of sub strings selected from Y) * S + (number of sub strings
selected from reversed Y) * R = (4*3) + (1*5) = 17
Example 2
Input
abcdef
pafedexycbc
42
Output
Explanation
For forming the string abcdef from pafedexycbc, select the sub string 'a' from
reversed Y, bc from reversed Y, def from reversed Y. No other selections can give
less than three sub strings.
String Factor = (number of sub strings selected from Y) * S + (number of sub strings
selected from reversed Y) * R = (0*4) + (3*2) = 6
Prabhu excels at typing letters but struggles with symbols and numbers. To simplify,
he decided to represent mathematical expressions using words. For numbers, he
mentions each digit individually with the character 'c' to signify the entire word
representing the number. Prabhu exclusively uses lowercase letters as he's not
proficient with shift keys or caps lock.
For instance
Note:
Constraints
0 < Characters in the first line including space < 100
Input
Single line denoting the expression.
Output
Single integer repersenting the result of the expression evalutated in numbers not in
words.
Examples
Input
Output
Explanation
In word twochundred, hundred is not a valid word only zero to nine can be used
Example 2
Input
Explanation
Everywords in the expression is valid but the expression cannot be evaluated only
mul operation is found there. After executing, there are still other words are left so
the expression is not complete or invalid
Example 3
Input
Ouput
22
Explanation
You are a project manager in a large IT company. You need to select a team of
employees to work on a project. You have a list of employees who are eligible for the
selection. Employees are indexed from 1 to N.
However, there is a certain rule that must be followed in order to select the team.
There are some employees who have some personal conflicts and they can't be in a
team together. Also, each employee has a skill value assigned to them, representing
their level of expertise. As a project manager, your task is to select a team of
employees such that the total expertise of the team should be maximum, keeping
the employees incompatibility in mind. Two employees are said to be incompatible if
they have any conflicts among them.
Given the employees, their level of expertise value and employee pairs with
conflicts, find the maximum possible expertise of the team.
Constraints
1 <= n <= 1000
Input
First line consists of two integers n,c separated by space, representing the number
of employees and number of pairs having conflicts.
Next c lines, each consists of two integers separated by space. These represents the
id of the employees having conflicts between them.
Last line consists of n integers separated by space, where ith integer represents the
expertise level of ith employee.
Output
Print a single integer denoting the maximum possible expertise of the team.
Examples
Example 1
Input
86
12
25
36
68
14
78
75431629
Output
21
Explanation
You can form a team with employees [3, 1, 5, 8] who don't have any conflicts among
themselves and the total expertise of the team is the sum of skill values of all
employees i.e., 4+7+1+9 = 21. No other combination of employees will give an
expertise which is greater than 21.
Example 2
Input
10 4
15
39
25
7 10
2 6 3 8 12 9 7 14 1 10
Output
56
Explanation
You can form a team with employees [5, 10, 3, 4, 6, 8] who don't have any conflicts
among themselves and the total expertise of the team is the sum of skill values of all
employees i.e., 12+10+3+8+9+14 = 56. No other combination of employees will
give an expertise which is greater than 56.
To determine the optimal borewell locations, Salva has gathered surface data for the
region. The goal is to identify the best place for borewells based on the
characteristics of the valleys. During rainfall, water accumulates in the valleys and
seeps into the ground, making valleys with a wider span more likely to contain
underground water.
In the context of this region, a valley is the space between peaks, and a peak is
defined as the highest point in the surrounding region - a local maximum in
mathematical terms.
where Y represents the height of the surface from the measuring level at a distance
x from the measuring point. The measuring point is the origin, (0,0), and
measurements are taken towards the positive x-axis. The region under consideration
has a length of 2pi. For clarity, consider 2*pi as 6.2831.
From the provided data, the task is to identify the widest valley. The widest valley is
characterized by the maximum horizontal distance between its corresponding peaks
or maximas. The output should indicate the count of the valley from the left. If there
are multiple valleys with the same width, the leftmost one should be reported. The
result should be presented with an accuracy of up to four decimal places.
Constraints
2 <= N <= 25
Second line contains 'n' space separated integers representing elements of array A
Third line contains 'n' space separated integers representing elements of array B
Output
Single integer denoting which valley is suitable to lay the bore counting from the
Start. Local maxima should be accurate upto four decimal places.
Examples
Input
12
23
Output
Explanation
y = sin(x + 2) + sin(2x + 3)
The first valley is in between the peak A and B, the second valley is between the
peak B and C. The second valley is the widest. So, the output is 2
Example 2
input
123
111
output
Explanation
We have a classic number-placement puzzle for you! This puzzle is played on a 9x9
matrix, divided into nine 3x3 sub matrices.
In this matrix some cells are pre-filled, some cells are provided with hints, while the
other cells are empty. You have to fill these empty cells. Rules for filling the puzzle
are given below.
Every 3*3 sub matrix should have 1-9 numbers without repetition. The
sub matrices are highlighted with thick boarders in the given figures in
example section.
There are some cells which are provided with hints i.e., those cells
should be filled with one of the numbers from the given list in the
input.
Tina is participating in this puzzle competition, and due to time constraints, in the
last minutes, she quickly filled in the puzzle but might have made some mistakes.
But the organizers felt none of them might have solved correctly and decided to rank
the participants based on the number of cells that require replacements with other
numbers to make the grid correct. The fewer the count of such cells, the better their
rank will be. Fortunately, if Tina filled the whole thing correctly, then she will win the
puzzle. If the count of cells that need modifications is <= given K, then Tina will get
a rank and has the chance of winning. Judge will compare the closest solution based
on individual answer to minimize the number of cells need to be changed. Its
impossible for her to win, if count of cells that need modifications is greater than
given K, because she won't get into the ranking list.
Given puzzle filled by Tina, a list of numbers, and an integer 'K', determine whether
Tina has a chance of winning the competition or not.
Note : You can only change the hinted and empty cell values but not pre-filled cells
in order to make the grid correct.
Constraints
Grid size remains same i.e., 9x9.
Grid values will be basically from 1-9. But we use leading 0s to represent empty cells
and trailing 0s to represent hinted cells.
1 <= K <= 10
Input
First 9 lines consists of 9 space separated numbers denoting the matrix, filled by
Tina where,
If a number has a leading zero, it means the cell was filled by Tina.
If a number has a trailing zero, it indicates that it's a hinted cell, and it
should be filled with one of the numbers from the given input list.
10th line consists of a list of numbers which are allowed to be placed into the hinted
cells.
The 11th line of input contains an integer 'K,' which represents the maximum
number of cells that are allowed to have incorrect values while still being eligible for
a ranking in the competition.
Output
Print "Won" if Tina placed everything correctly else,
If she didn't win but has a chance of winning, print the indices of the
cells that are wrongly placed, arranged from top to bottom and left to
right, each on a single line (0 based indexing).
Examples
Example1
Input
06 1 09 7 4 02 03 5 08
4 50 7 08 03 01 6 09 2
8 2 04 6 09 05 01 7 4
20 03 06 04 1 09 5 08 07
5 09 01 2 07 08 04 06 3
07 08 4 03 5 06 20 01 9
9 6 02 01 08 3 07 4 5
3 04 05 09 06 07 8 20 1
01 7 08 50 2 4 01 3 6
572
Output
2 2
86
Explanation
The above grid which is filled by Tina is incorrect because of the following reasons.
o 4 is present twice in the first 3*3 sub grid, 3 rd column and also in
3rd row (1-based indexing, from top left)
o 1 is present twice in the last 3*3 sub grid (9th), 7 th column and
also in 9th row (1-based indexing, from top left)
In order to make this grid correct in minimum replacements, we will place 3 in the
position (2,2) and 9 in the position (8,6). Since the number of cells that are needed
to be modified is less than K, she holds the chance of winning and hence we print the
cells indices which require modifications, in left to right, top to bottom order.
Example 2
Input
5 3 04 60 7 08 09 01 01
6 07 02 1 9 5 03 04 08
01 9 8 03 04 02 05 6 07
8 05 09 70 6 01 04 02 3
4 02 60 8 05 3 07 09 1
7 01 03 09 2 04 08 05 6
09 6 10 05 01 07 2 8 04
02 08 07 4 1 9 06 03 5
07 04 05 02 8 06 10 7 9
6712
Output
Impossible
Explanation