Codevita
Codevita
Problem Description
The problem solvers have found a new Island for coding and named it as Philaland.
These smart people were given a task to make purchase of items at the Island easier by distributing various
coins with different value.
Manish has come up with a solution that if we make coins category starting from $1 till the maximum price of
item present on Island, then we can purchase any item easily. He added following example to prove his point.
Lets suppose the maximum price of an item is 5$ then we can make coins of {$1, $2, $3, $4, $5} to purchase
any item ranging from $1 till $5.
Now Manisha, being a keen observer suggested that we could actually minimize the number of coins required
and gave following distribution {$1, $2, $3}. According to him any item can be purchased one time ranging
from $1 to $5. Everyone was impressed with both of them.
Your task is to help Manisha come up with minimum number of denominations for any arbitrary max price in
Philaland.
Constraints
1<=T<=100
1<=N<=5000
Input Format
First line contains an integer T denoting the number of test cases.
Next T lines contains an integer N denoting the maximum price of the item present on Philaland.
Output
For each test case print a single line denoting the minimum number of denominations of coins required.
Test Case
Explanation
Example 1
Input
10
5
Output
Explanation
But as per Manisha only {$1, $2, $3, $4} coins are enough to purchase any item ranging from $1 to $10.
Hence minimum is 4. Likewise denominations could also be {$1, $2, $3, $5}. Hence answer is still 4.
But as per Manisha only {$1, $2, $3} coins are enough to purchase any item ranging from $1 to $5. Hence
minimum is 3. Likewise denominations could also be {$1, $2, $4}. Hence answer is still 3.
Sona A
05Hr 58Min 25Sec
Guidelines
Coding Area
Editor | Compile & Run History
Submissions
Feedback Form
Graphs
Coding Area
ONLINE EDITOR (B)
A
B
C
D
E
F
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.
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
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
CONNECT WITH US
Sona A
05Hr 57Min 55Sec
Guidelines
Coding Area
Editor | Compile & Run History
Submissions
Feedback Form
Graphs
Coding Area
ONLINE EDITOR (C)
A
B
C
D
E
F
Balancing Stars
Problem Description
CODU loves to play with string of brackets.
He considers string as a good string if it is balanced with stars. A string is considered as balanced with stars if
string contains balanced brackets and between every pair of bracket i.e. between opening and closing brackets,
there are at least 2 stars(*) present. CODU knows how to check whether a string is balanced or not but this
time he needs to keep a track of stars too. He decided to write a program to check whether a string is good or
not. But CODU is not as good in programming as you are, so he decided to take help from you. Will you help
him for this task? You need to print Yes and number of balanced pair if string satisfies following
conditions(string is good if it satisfies following 2 conditions):
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.
CONNECT WITH US
Sona A
05Hr 54Min 18Sec
Guidelines
Coding Area
Editor | Compile & Run History
Submissions
Feedback Form
Graphs
Coding Area
ONLINE EDITOR (D)
A
B
C
D
E
F
Market Survey
Problem Description
Market Research firm is carrying out a survey regarding popular brands. The person who has the best pulse of
the survey population will be rewarded by the firm.
The survey comprises of N questions was taken by M participants, not at the same time but one after the other.
Clearly, there is no correct answer since it is a survey of brands. Each question can have only four options
(1,2,3,4). Most expected answers to different questions is used as a template to measure brand popularity.
Think of this as a default answer sheet where the question paper is the Survey.
'0' represents no answer to a question. Thus it means that the participant has skipped answering that question.
Right Answer:
For a particular question, the highly chosen option till that point of time is treated as the correct answer. If
multiple options have the same count, then out of those options the one which was chosen recently is treated as
the right answer.
Score of a Participant:
One point will be awarded for each right answer. No negative points for wrong answers.
Instant Result:
This is shared to the Participant instantly after completion of his/her exam. (this is equal to number of right
answers)
Final Result:
Only the final top scorer(TOPPER) is announced along with his score.
Note:
At the end of all M Participants completing the exam, the final right answers gets decided.
Based on these answers score of each candidate gets recalculated and the one with highest score is the
TOPPER!!!
If more than one Participant gets the top score then the one among them who attempted the exam first, is
treated as TOPPER.
Constraints
1 <= N,M <= 1000
Input Format
First line contains N (number of questions)
Output
First M lines showing the instant results of each Participant.
Explanation
Example 1
Input
10
1234123412
1244323113
2344123112
Output
18
Explanation
Number of questions = 10
Number of Participants = 2
Default answers : 1 2 3 4 1 2 3 4 1 2
Latest Key : 1 2 4 4 3 2 3 1 1 3
Latest Key : 1 2 4 4 1 2 3 1 1 2
Final key : 1 2 4 4 1 2 3 1 1 2
(Final Key is same as Latest Key at the end of all Participants completing the exam)
CONNECT WITH US
Sona A
05Hr 53Min 55Sec
Guidelines
Coding Area
Editor | Compile & Run History
Submissions
Feedback Form
Graphs
Coding Area
ONLINE EDITOR (E)
A
B
C
D
E
F
Grooving Monkeys
Problem Description
N monkeys are invited to a party where they start dancing. They dance in a circular formation, very similar to a
Gujarati Garba or a Drum Circle. The dance requires the monkeys to constantly change positions after every 1
second.
The change of position is not random & you, in the audience, observe a pattern. Monkeys are very disciplined
& follow a specific pattern while dancing.
This array (1-indexed) is the dancing pattern. The value at monkeys[i], indicates the new of position of the
monkey who is standing at the ith position.
Given N & the array monkeys[ ], find the time after which all monkeys are in the initial positions for the 1st
time.
Constraints
1<=t<=10 (test cases)
Input Format
First line contains single integer t, denoting the number of test cases.
Next line contains N integer denoting the dancing pattern array, monkeys[].
Output
t lines,
Each line must contain a single integer T, where T is the minimum number of seconds after which all the
monkeys are in their initial position.
Test Case
Explanation
Example 1
Input
365412
Output
Explanation
Suppose monkeys are a,b,c,d,e,f, & Initial position (at t = 0) -> a,b,c,d,e,f
At t = 1 -> e,f,a,d,c,b
a will move to 3rd position, b will move to 6th position, c will move to 5th position, d will move to 4th
position, e will move to 1st position and f will move to 2nd position. Thus from a,b,c,d,e,f at t =0, we get
e,f,a,d,c,b at t =1. Recursively applying same transpositions, we get following positions for different values of
t.
At t = 2 -> c,b,e,d,a,f
At t = 3 -> a,f,c,d,e,b
At t = 4 -> e,b,a,d,c,f
At t = 5 -> c,f,e,d,a,b
At t = 6 -> a,b,c,d,e,f
CONNECT WITH US
Sona A
05Hr 53Min 37Sec
Guidelines
Coding Area
Editor | Compile & Run History
Submissions
Feedback Form
Graphs
Coding Area
ONLINE EDITOR (F)
A
B
C
D
E
F
Home Lighting
Problem Description
You are moving to a new apartment and want to plan your total lighting cost for the next 2 years which
includes the cost of bulb procurement and cost of electricity consumption. Three types of bulbs are available in
the market.
1. Regular bulbs, which cost C1, have a warranty of M1 hours, and have a running cost of R1 per hour
2. CFL bulbs, which cost C2, warranty M2 hours, running, cost R2 per hour
3. LED bulbs, which cost C3, warranty M3 hours, running cost R3 per hour
C1 < C2 < C3 and R1 > R2 > R3, nothing can be said about M1, M2, and M3.
You have a plan for 1 bulb in the kitchen at H1 hours per day, 2 bulbs per room across 3 rooms at H2, H3, H4
hours per day per room per bulb, 1 bulb for bathroom at H5 hours per day.
When you prepare your budget you assume that it will last only till the warranty period.
Given the above requirements, come up with a bulb procurement plan that incurs least cost over 2 years -
where cost includes procurement and running cost. In case warranty expires, in your model assume that the
bulb will need to be replaced. Also assume that you will move out after 2 years, and so you are not concerned
about stretching the life of bulbs beyond that time. Assume that there are 365 days in each year.
Constraints
C1 < C2 < C3
R1 > R2 > R3
0<= Warranty<=150
0<= H1,H2,H3,H4,H5<=24
Input Format
The first three lines contains three integers denoting Fixed cost, Warranty and running cost of regular bulb,
CFL and LED respectively.
The next five lines contain one integer each denoting usage hours of rooms (H1, H2, H3, H4, H5)
Output
Minimum cost to light the house.
Test Case
Explanation
Example 1
Input
50 1500 16
100 8000 14
400 25000 1
1
14
Output
38500
Explanation
Minimum cost for meeting all the lighting requirement of house is 38500.
Example 2
Input
50 10000 16
100 8000 14
800 25000 1
10
Output
41960
Explanation
Minimum cost for meeting all the lighting requirement of house is 41960.
CONNECT WITH US