Codathon 1styr Prelims
Codathon 1styr Prelims
Problem:
In a remote village, there are three competing fruit vendors: AppleEats,
BananaBonanza, and CherryChoice. Each vendor has a different number of
customers waiting in line: AppleEats has A customers, BananaBonanza has B
customers, and CherryChoice has C customers.
A vendor is said to have a 'customer advantage' if they have more customers in line
than the combined number of customers at the other two vendors. Can you
determine if any vendor has a customer advantage in this scenario?"
Input Format:
● The first line of input will contain a single integer T, denoting the number of
test cases.
● Each test case consists of a single line of input containing three space
separated integers A,B,C denoting the no of customers to three vendors
respectively.
Output Format:
For each test case, output YES if any of the companies has a monopolistic
advantage over its competitors, else output NO.
Constraints:
● 1<=T<=1000
● 1<=A,B,C<=10
Example:
Input:
4
111
124
2 10 3
123
Output:
NO
YES
YES
NO
Explanation:
● Test case 1: All the vendors have equal no of customers so none have a
customer advantage.
● Test case 2: The third vendor has a customer advantage as 1+2<4.
● Test case 3: The second vendor has a customer advantage as 2+3<10
Test Cases:
TC(1):
Input:
3
836
10 4 3
885
Output:
NO
YES
NO
TC(2):
Input:
6
541
555
10 2 3
689
154
759
Output:
NO
NO
YES
NO
NO
NO
TC(3):
Input:
10
896
156
789
654
1 5 10
783
248
169
563
789
Output:
NO
NO
NO
NO
YES
NO
YES
YES
NO
NO
"Congratulations! You've just been granted a magical genie lamp by Aladdin himself,
right before your big coding interview at XYZ Pvt. Ltd. tomorrow at 9 AM. But here's
the twist: your current interview score, N, can only consist of the digits 7 and 9.
Aladdin's genie is feeling mischievous today and has granted you the power to
upgrade your score, but with a hilarious twist. You can only convert 7 to 9 or 9 to 7.
So, use the power and find the maximum score you can achieve. Remember, you can
only change at most one digit. Good luck, and may your interview score shine
brighter than a genie's lamp!"
Input:
Input begins with an integer T,the number of test cases.Each test case consists of an
integer N(score).
Output:
Single line output ,the maximum score you can get by changing at most one digit.
Constraints:
1 <= N <= 10^9
Sample Example
Input:
1
9779
Output:
9979
Explanation:
Changing the first digit results in 7779.
Changing the second digit results in 9979.
Changing the third digit results in 9799.
Changing the fourth digit results in 9777.
The maximum number is 9979.
TestCase-1(1 points)
Input:
3
777
999
9797
Output:
977
999
9997
TestCase-2(2 points)
Input:
5
97997
77799
999977
999999
9999799
Output:
99997
97799
999997
999999
9999999
TestCase-3(2 points)
Input:
8
7
77799
97997777
79799
999977
999999
9997799
77979799
Output:
9
97799
99997777
99799
999997
999999
9999799
97979799
Count Gifts
Problem (Medium)(20->4,4,4,4,4)
It's the morning of December 25th, and you and your friend have just received your
gifts from Santa Claus. Excitedly, you both start unwrapping your gifts and counting
how many gifts each of you received.
As you're counting, you wonder how well each of you did compared to the other. You
decide to play a game and figure out, for each person, how many others received
fewer gifts than them.
Given an array of positive integers representing the number of gifts received by each
friend, your task is to find, for each person, how many other friends received fewer
gifts than them.
Input
Input begins with an integer T,the number of test cases.Each test case consist of an
integer N number of friends and an array of positive integers representing the
number of gifts received by each friend.
Output
For each test case,output a restaurant array with the count of gifts.
Constrains
1<=T<=100
1<=N<=1000
Sample 1:
Input
1
4
5 261
Output
2110
Explanation:
● For the first person with 5 gifts, there are 2 people (persons 2 and 3) who
received fewer gifts.
● For the second person with 2 gifts, there is 1 person (person 3) who received
fewer gifts.
● For the second person with 2 gifts, there is 1 person (person 3) who received
fewer gifts.
● For the fourth person with 1 gift, no one received fewer gifts.
RCCIIT is organizing a book club meeting and wants to distribute books and
divided equally among the attendees. Find the maximum possible number of
Note that every book and magazine must be distributed, and there cannot be any left
over.
For example, there are 4 books and 8 magazines, RCCIIT can distribute them
equally to two attendees, where each attendee receives 2 books and 4 magazines.
However.
Input Format: The first line of input will contain a single integer T, denoting the
number of test cases.The first and only line of each test case contains two
respectively.
Output:For each test case, output on a new line the answer: the maximum number of
attendees such that everyone receives an equal number of books and magazines.
Constraints:
● 1<=T<=1000
● 1<=N,M<=10^9
Example:
Input
3
15
24
46
Output:
1
2
2
Test Cases
TC(1):(2)
Input:
3
99
27
3 15
Output:
9
1
3
TC(2):(2)
Input:
8
1752 45648
2154 5646
56 56
8489 4562
7899 4876
4521 78994
1000 5000
6000 78485
Output:
24
6
56
1
1
1
1000
5
TC(3):(2)
Input:
12
1547 1798
415647 478476
4646 4897431
564416 4156474
45876141 65497613
526 128
720 81
625 25
99
33
12 18
144 12
Output:
1
9
1
2
1
2
9
25
9
3
6
12
TC(4):(4)
Input:
15
8645 4646
45645645 47744456
123464 7456486
13465 25485
2147 4644
877556 41568
21464 4644321
134646 457476
877847 45648
64 8
45 45
78 54
1346 1464
1546 446
Output:
1
1
2
5
1
4
1
6
1
8
45
6
2
2
2
TC(5):(5)
Input:
20
96646 479764
15646 447641
489478 4474
4156478 4947897
461416 713787
5616456 789544
489476 791231
999999 88888
9879485 98787
48979875 45967976
97874 78978
78956 1489476
46547631 14613
784215 848946
87978 684897
8459 4556
52146 18944
121 121
625 25
25 652
Output:
2
1
2
1
1
8
1
1
1
1
2
4
3
3
3
1
2
121
25
1
Your mission is to navigate through this galaxy and collect as much energy as
possible. Here's how it works:
1. Each row in the Star Matrix represents a different sector of the galaxy, and each
column represents a star in that sector.
2. In each sector (row), you can only collect energy from one star at a time. To make
it exciting, you decide to choose the star with the highest energy level in each sector.
In case of a tie, you can choose any tied star; it doesn't matter which one.
3. After collecting energy from the stars in a sector, you calculate the highest energy
level among all the stars you've collected so far and add it to your spaceship's energy
score.
4. You repeat this process until you've collected energy from all the stars in the
galaxy or matrix.
Your goal is to maximise your spaceship's energy score by cleverly choosing the
stars in each sector. Once you've completed your mission, return the final energy
score as a testament to your success in exploring the galaxy.
Constraints:
● 1<=starMatrix.length<=300
● 1<=starMatrix[i].length<=500
● 0<=starMatrix[i][j]<=10^3
Input:
Input begins with an integer T,the number of test cases.Each test case consists of
integer R(row) and integer C (column) of the Star Matrix , and positive integers for
this R*C Star Matrix which represents the energy levels of stars in the galaxy.
Output:
Single line output for each test case of the final maximum spaceship's energy score.
Example:
Input:
1
33
721
642
653
321
Output :
15
Explanation: In your thrilling space adventure, you start by collecting energy from
stars with values 7, 6, 6, and 3. You add the highest value, 7, to your spaceship's
energy score. Then, you proceed to collect energy from stars with values 2, 4, 5, and
2, adding the highest value, 5, to your score. Finally, you collect energy from stars
with values 1, 2, 3, and 1, adding the highest value, 3, to your score. Your final energy
score is 7 + 5 + 3 = 15, a fantastic achievement in your intergalactic quest!
Test Cases:
TC-1(3):
Input:
2
34
0216
9658
45 12 8 0
11
1
Output:
70
1
TC-2(3)
Input:
3
44
10 7 15 12
18 14 16 20
21 22 11 13
17 19 23 24
35
15496
38274
67135
64
15 12 18 20
10 8 25 22
30 28 32 35
40 38 45 42
50 48 55 52
60 58 65 62
Output:
83
27
245
TC-3(3):
Input:
3
46
10 7 15 12 16 17
18 14 16 20 14 12
21 22 11 13 8 89
17 19 23 24 12 325
33
50 40 60
30 70 20
80 10 90
9 10
8 1 6 7 7 9 7 10 8 10
2 8 9 3 7 5 10 8 10 5
6995441744
6422577321
6 5 9 5 2 10 6 10 10 2
9 8 9 7 9 10 6 6 9 10
5779854791
3 4 6 7 10 7 4 7 9 4
1 8 10 7 9 10 7 10 2 10
Output:
420
210
85
TC-4(6)
1
13 14
1 8 16 15 12 9 15 11 18 6 16 4 9 4
3 19 8 17 19 4 9 3 2 10 15 17 3 11
13 10 19 20 6 17 15 14 16 8 1 17 0 2
12 20 0 19 15 10 7 10 2 6 18 7 7 4
17 14 2 2 10 16 15 3 9 17 9 3 17 10
17 6 19 17 18 9 14 2 19 12 10 18 7 9
5 6 5 1 19 8 15 2 2 4 4 1 2 17
12 16 8 16 7 6 18 13 18 8 14 15 20 11
2 10 19 3 15 18 20 10 6 7 0 8 3 7
11 5 10 13 1 3 4 7 1 18 20 17 19 2
0 3 20 6 19 18 3 12 2 11 3 1 19 0
6 5 3 15 6 1 0 17 13 19 3 8 2 7
2 20 9 11 13 5 1 16 14 1 19 3 12 6
Output:
190