0% found this document useful (0 votes)
8 views9 pages

Sample Question

The document outlines four distinct problems involving data processing and decision-making based on specific criteria. Problem 1 involves determining the most popular post on Facebook based on likes and comments. Problem 2 focuses on maximizing the number of girls impressed by a runner within a specified distance, while Problem 3 calculates prize money based on chess game outcomes, and Problem 4 computes the total cost of groceries based on freshness values.

Uploaded by

hailchiku6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Sample Question

The document outlines four distinct problems involving data processing and decision-making based on specific criteria. Problem 1 involves determining the most popular post on Facebook based on likes and comments. Problem 2 focuses on maximizing the number of girls impressed by a runner within a specified distance, while Problem 3 calculates prize money based on chess game outcomes, and Problem 4 computes the total cost of groceries based on freshness values.

Uploaded by

hailchiku6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

PROBLEM:1

A post on Facebook is said to be more popular if the number of likes on the post is strictly gr
eater than the number of likes on some other post. In case the number of likes is same, the
post having more comments is more popular.

Given arrays A and B, each having size N, such that the number of likes and comments on t
he ith post are A and B, respectively, find out which post is most popular.

It is guaranteed that the number of comments on all the posts is distinct.

Input Format

• The first line of input will contain a single integer T, denoting the number of test cases.

• Each test case consists of multiple lines of input.

• The first line of each test case contains a single integer N, the number of posts.

• The second line of each test case contains N space-separated integers A1, A2,..., AN - wh
ere A is the number of likes on the it post.

• The third line of each test case contains N space-separated integers B1, B2, the number of
comments on the post. BN-where B₁ is

Output Format

For each test case, output on a new line, an integer in the range 1 to N, denoting the index o
f the post which is most popular among the N posts.

Constraints

• 1 ≤ T≤1000

• 1 ≤ N ≤ 10^5

• 1 A, B ≤2.10^5

• The elements of array B are distinct.

• It is guaranteed that the sum of N over all test case does not exceed 2.10^5

Sample 1:
Input

4
3

544

123

10 109

254

339

913

2815

2819

Output
1
2
3
2
Explanation:

Test case 1: The number of likes on the first post is greater than that of second and third pos
t. Thus, the first post is most popular.

Test case 2: The first and second post have maximum number of likes. But, the second post
has more

comments than the first post. Thus, the second post is most popular.

Test case 3: The number of likes on the third post is greater than that of first and second pos
t. Thus, the third post is most popular.

Test case 4: The number of likes on the second post is greater than that of first, third, and fo
urth post. Thus, the second post is most popular.

TEST CASE1:
INPUT 1:
4
3
544 123
10 109
3
10 109
254
3
339 913
4
2815 2819 2818 2816
1234
Output 1:
1
2
1
2
TEST CASE2:
Input 2:
2
5
100 200 150 180 120
20 10 30 25 15
4
50 70 60 80
20 30 25 15
Output 2:
3
4
TEST CASE 3:
Input 3:
3
2
200 300
10 20
3
100 200 150
20 30 15
3
500 400 300
30 20 10
Output 3:
2
2
1
Input 4:
1
6
100 150 200 250 300 350
10 20 30 40 50 60
Output 4:
6

PROBLEM:2
Vishal loves running. He often visits his favourite Nehru Park and runs for very long distance
s. On one such visit he found that the number of girls in the park was unusually high. Now he
wants to use this as an opportunity to impress a large number of girls with his awesome spe
ed.

The track on which he runs is an N kilometres long straight path. There are aj girls standing
within the ith kilometre of this path. A girl will be impressed only if Vishal is running at his ma
ximum speed when he passes by her. But he can run at his best speed only for a single cont
inuous stretch of K kilometres. Now Vishal wants to know what is the maximum number of gi
rls that he can impress.

###Input First line of the input contains the number of testcases T.

For each test case,

First line contains two space-separated integers N and K, the length of the track and the max
imum distance he can run at his best speed.

Second line contains N space-separated integers, the number of girls within each kilometre
of the track.

###Output For each test case print one line containing an integer, denoting the maximum nu
mber of girls Vishal can impress.

###Constraints 1≤T≤10

1≤K≤N≤100

1 ≤ a ≤ 100
Sample 1:
1
72
2481218

Output
12
Explanation
He can impress 4+8=12 girls if he runs at his best speed between the 2nd and the 3rd kilom
etre, inclusive.

TEST CASE
Input:
1
10 4
3256132452

Output:
16

PROBLEM:3
The annual Chess Championship 2024 is set to commence, featuring 14 classical games bet
ween two renowned players - Magnus and Kasparov. Each game could result in a victory for
Magnus (denoted by 'M'), a victory for Kasparov (denoted by 'K'), or a draw (denoted by 'D').
At stake is a total prize pool of $100,000.
The prize distribution follows a unique scheme:
If one player accumulates more points than the other after the 14 games, the winner receiv
es 60% of the prize pool, while the runner-up gets the remaining 40%.
In case of a tie in points, Magnus, the defending champion, is declared the winner. Howev
er, in this scenario, the winner and the runner-up receive 55% and 45% of the prize pool, res
pectively.
Given the results of all the 14 games and the total prize pool, your task is to determine the pr
ize money Magnus receives.
Input Format:
The first line contains an integer T denoting the number of test cases.
For each test case:
The first line contains an integer representing the total prize pool X.
The second line contains the results of the 14 games as a string consisting of 'M', 'K', and
'D'.
Output Format:
For each test case, output the total prize money won by Magnus.
Constraints:
1 ≤ T ≤ 1000
1 ≤ X ≤ 100000
The string representing game results will have a length of 14 and consist only of 'M', 'K', an
d 'D'.
Sample input:
3
80000
KKMKMKMKMKMKMD
60000
MMMMMMMMMMMMMM
50000
KKKKKKKKKKKKKK
Sample output
48000
48000
27500

Explanation:
In the first test case, Magnus wins 6 games, Kasparov wins 4, and there are 4 draws. Henc
e, Magnus is declared the winner and receives 60% of the prize pool, which is $48,000.
In the second test case, Magnus wins all 14 games, resulting in a tie with the maximum po
ssible points. According to the rules, he retains his championship title, but the prize money is
reduced to 55% of the pool, yielding $48,000.
In the third test case, Kasparov wins all 14 games, making him the clear winner with no tie.
Magnus receives 40% of the prize pool, amounting to $27,500

TEST CASE1:
INPUT1:
1
80000
KKMKMKMKMKMKMD

OUTPUT1:
48000

TEST CASE2:
INPUT2:
1
60000
MMMMMMMMMMMMMM
OUTPUT2:
48000

TEST CASE3:
INPUT3:
1
50000
KKKKKKKKKKKKKK
OUTPUT3:
27500
PROBLEM:4
Tom visited a grocery store for fresh supplies. There are N items in the store where the ith it
em has a freshness value A; and cost B.

Tom has decided to purchase all the items having a freshness value greater than or equal to
X. Find the total cost of the groceries Tom buys.

Input Format

• The first line of input will contain a single integer T, denoting the number of test cases.

• Each test case consists of multiple lines of input.

• The first line of each test case contains two space-separated integers N and X - the numbe
r of items and the minimum freshness value an item should have.

• The second line contains N space-separated integers, the array A, denoting the freshness
value of each item.

• The third line contains N space-separated integers, the array B, denoting the cost of each it
em.

Output Format

For each test case, output on a new line, the total cost of the groceries Tom buys.

Constraints

1 ≤ T ≤ 100

1 ≤ N, X ≤ 100

1 ≤ A, B ≤ 100

Solution 1:
INPUT
4
2 20
15 67
10 90
31
123
123
3 100
10 90 50
30 7 93
4 50
12 78 50 40
40 30 20 10

OUTPUT
90
6
0
50

Explanation:

Test case 1: Item 2 has freshness value greater than or equal to X = 20. Thus, Tom buys ite
m 2. The total cost is 90.

Test case 2: Items 1, 2, and 3 have freshness value greater than or equal to X = 1. Thus, To
m buys all 3 items. The total cost is 1+2+3=6.

Test case 3: No item has freshness value greater than or equal to X = 100. Thus, Tom buys
no items.

Test case 4: Items 2 and 3 have freshness value greater than or equal to X = 50. Thus, Tom
buys items 2 and 3. The total cost is 30 + 20 = 50
TEST CASE1:
Input:
1
2 20
15 67
10 90

Output:
90
TEST CASE2:
Input:
1
31
123
123

Output:
6
TEST CASE3:
Input:
1
3 100
10 90 50
30 7 93

Output:
0
TEST CASE4:
Input:
1
4 50
12 78 50 40
40 30 20 10

Output:
50

You might also like