You are on page 1of 9

Medallia Argentina Inter… 150 minutes

Question - 1 SCORE: 100 points


Getting the third person with best salary

Given N people with the following features:


Id
Salary
Number of children
Civil Status
Age
We want you to return the id of the person with the third best
final salary between the group of people that fulfill the next
conditions:
Being single.
Having 1 to 3 children.
Having between 30 and 40 years old
where the final salary is obtained with the following formulae:
A first discount of 15 percent of the salary and after that
another discount of max(0, (4 - amount of children)) percent
of the previous result.

For example if a person has 3 children and his salary is 100, his
final salary will be of 84.15.
First step: 100 - 100 * 0.15 = 85
Second step: 85 - 85 * 0.01 = 84.15

You can assume there will always be at least 3 people in the list
that fulfill the conditions requested above and there won't be
ties.

Input Format
Input is already parsed by us. The format is only
important if you want to use the ‘Custom input’ option.
The first line contains an integer, n, denoting the number of
people.
For each person there will be 5 lines, one for each feature in the
order they appear above.

Constraints
1 ≤ n ≤ 106
1 ≤ salary ≤ 106
civil status ∈ {divorced, single, widowed}
0 ≤ number of children ≤ 5
20 ≤ age ≤ 60

Output Format
The function must return the id of third person with best salary.

Sample Input 0

5
1
100
2
single
32
2
1000
2
single
30
3
10000
3
single
40
4
1000000
2
single
39
5
12
1
divorced
34

Sample Output 0

Question - 2 SCORE: 100 points


Palindromic Multiples

Maths Easy

Given an integer n, we want you to find the amount offour digit


numbers divisible by n that are not palindromes.

A palindromic number is a number that remains the same when


its digits are reversed. Like 1661, for example, it is
"symmetrical".

For example, if n equals 4000, the only four digit numbers


divisible by 4000 are 4000 and 8000. Neither of those numbers
is a palindrome, so the answer would be 2.
If n equals 2002, then the only four digit numbers divisible by
2002 are 2002, 4004, 6006 and 8008. As all of them are
palindromes, the answer would be 0.

Complete a function named nonPalindromicMultiples that


receives an integer n. It should return the amount offour digit
numbers divisible by n that are not palindromes.

Constraints

n>0

Input Format
Important: input is already parsed by us. The format is only
important if you want to use the ‘Custom input’ option.
Input consists of one integer number, denotingn.

Output Format
Return an integer number equal to the amount offour digit
numbers divisible by n that are not palindromes.

Sample Input 0

4000

Sample Output 0

Sample Input 1

2002

Sample Output 1
0

Question - 3 SCORE: 100 points


Most Frequent Number

Arrays Easy

You are given a list of n numbers, and you must return the most
repeated one. If there is more than one, then return the smallest
one.

Input Format
Important: input is already parsed by us. The format is only
important if you want to use the ‘Custom input’ option.

The first line contains an integer, n, denoting the amount of


numbers.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains
an integer describing xi.

Constraints
1 ≤ n ≤ 106
0 ≤ xi ≤ 109

Output Format
The function must return the smallest among the most repeated
numbers.

Sample Input 0

4
1
2
3
3

Sample Output 0

Sample Input 1

9
1
2
3
1
2
3
4
2
3

Sample Output 1

Sample Input 2

5
0
0
1
1
2
Sample Output 2

Question - 4 SCORE: 100 points


Billing Phonecalls

Easy OOP

We are now working for a phone services provider, and want to


update our billing software. There are three different types of
phone calls:

Local phone calls: both caller and receiver are in the same
city
National phone calls: caller and receiver are in different
cities, but in the same country
International phone calls: caller and receiver are in different
countries

Our plans used to allow only local phone calls, and we want to
add both national and international to them. To do this, we need
to upgrade the software. Here is how each type of phone call
should be billed:

Local phone calls: $1 for each second the call lasts.


National phone calls: $10 if the call lasts one minute or less.
If it lasts more than one minute, then $10, plus $1 for each
second after the first minute.
International phone calls: $20 for each second. If the call
lasts more than 10 minutes, then a discount is made and it
costs $15 per second (this discount applies to the first 10
minutes also).

Input Format
Important: input is already parsed by us. The format is only
important if you want to use the ‘Custom input’ option.

The first line contains an integer, n, denoting the amount of calls


made.
Each of the n subsequent lines contains a string with the name
of the city where the ith call was made.
Then, each of the subsequent n lines contains a string with the
name of the city where the ith call was received.
Finally, n more lines that contain the duration of the ith call in
seconds.

Constraints
1 ≤ n ≤ 5 * 104
0 ≤ phone call durations ≤ 104
Cities names are in { Buenos Aires, Rosario, Viedma, Cusco,
Lima, Ayacucho, Rio de Janeiro, Belo Horizonte, Recife }
Buenos Aires, Rosario and Viedma are cities in Argentina.
Cusco, Lima and Ayacucho are cities in Peru.
Rio de Janeiro, Belo Horizonte and Recife are cities in Brazil.
All calls are measured in seconds

Output Format
The function must return n lines where the ith line has the total
cost of the ith call.

Sample Input 0

1
Buenos Aires
Buenos Aires
10
Sample Output 0

10

Sample Input 1

3
Cusco
Rio de Janeiro
Viedma
Cusco
Rio de Janeiro
Viedma
0
100
10000000

Sample Output 1

0
100
10000000

Sample Input 2

2
Buenos Aires
Rio de Janeiro
Rosario
Recife
50
61

Sample Output 2

10
11

Sample Input 3

2
Viedma
Lima
Cusco
Belo Horizonte
30
610

Sample Output 3

600
9150

Question - 5 SCORE: 100 points


Blood mixer

In a starship with N passengers intended to be humans, you


know that exactly one of them is an android pretending to be a
passenger, and you have to discover it as soon as possible.
An android is almost indistinguishable from a human, the only
way to distinguish them is by running a blood test that takes
many hours, and there is only one machine in the ship to run it.
Fortunately, a blood test can mix the blood of various subjects,
and the result will be positive if and only if one of the subjects is
an android.
Input Format
The input consists of an integer N, the number of passengers,
and a Test Machine object that performs the blood test with a
given set of passengers.
Each passenger is represented as a number between 0 and N-1.

Constraints:
1 ≤ N ≤ 106

Your objective is to run a series of blood tests over subsets


of passengers to discover the android in the shortest amount of
time.
Implementing an inefficient strategy would timeout, since each
test run suspends the execution for a while.

Output Format
The function must return an integer, the number representing
the android.

Question - 6 SCORE: 100 points


Shooting Efficiency

Maths

The shooting efficiency of a soccer player is the percentage of


goals scored over all the shots on goal taken in all his
professional career. It is a rational number between 0 and 100,
rounded to one decimal place (*). For example, a player who
made 7 shots on goal and scored 3 goals has a shooting
efficiency of 42.9.
Given the shooting efficiency of a player, we want to know which
is the minimum amount of shots on goal needed to get that
number (which must be greater than 0).

For example, if the shooting efficiency of Juan Roman Von


Neumann is 50, then it is impossible for him to only have one
shot on goal. That is because with only one shot, efficiency
would be either 0 (if he missed) or 100 (if he scored). With two
shots, though, he can achieve 50 (by having missed one and
scored the other).

Complete the function in the editor below. It has only one


parameter, the shooting efficiency of the player. The output
is the minimum amount of shots on goal needed to achieve that
efficiency.

(*) Standard rounding is used, so 99.81 and 99.849 are rounded


to 99.8; and 99.85 and 99.88 are rounded to 99.9.

Input Format
The input consists of a float between 0 and 100 with one decimal
place.

Output Format
The function must return an integer greater than 0.

Sample input 0

33.3

Sample output 0

Sample input 1

33.4
Sample output 1

287

Question - 7 SCORE: 100 points


The Taxman

Maths Logic Medium

George is a taxman. He must collect taxes from n taxpayers (cos


he's the taxman, yeah he's the taxman). George assigned each
taxpayer an unique ID number from 1 to n. Taxpayer i must pay
exactly i dollars. For example, taxpayer 1 will pay 1 dollar,
taxpayer 3 will pay 3 dollars, and so on. George is a very
organized man, so he will visit each taxpayer in order (i.e., from
1 to n) to collect their money. George is also a very superstitious
man. He never wants the current sum of collected money to be
equal to k. Because of that, George mayrefuse to take money
from some of the taxpayers. Given n and k, what is the
maximum amount of money he can collect?

Complete the maxMoney function in the editor below. It has two


parameters:
1. An integer, n, denoting the number of taxpayers.
2. An integer, k, denoting George's unlucky number.
The function must return an integer denoting themaximum
amount of money George can collect by visiting the taxpayers in
order of sequential ID number and ensuring that the current sum
of money collected is never equal to k. As the answer could not
fit in a 64 bit integer, return answer modulo (109 + 7).

Input Format
Input is already parsed by us. The format is only
important if you want to use the ‘Custom input’ option.
The first line contains an integer, n, denoting the number of
taxpayers.
The second line contains an integer, k, denoting George's
unlucky number.

Constraints
1 ≤ n ≤ 2 × 1012
1 ≤ k ≤ 4 × 1015

Output Format
The function must return an integer denoting the
maximum amount of money George can collect by visiting the
taxpayers in order of sequential ID number and ensuring that the
current sum of money collected is never equal to k. As the
answer could be large, return answer % (109 + 7). This is printed
to stdout by locked stub code in the editor.

Sample Input 0

2
2

Sample Output 0

Explanation 0
George visits the following sequence of n = 2 taxpayers:
1. George collects 1 dollar from taxpayer 1 to get sum = 1.
2. George collects 2 dollars from taxpayer 2 to get sum = 1 + 2
= 3; observe that he collected a maximum amount of money
and avoided having exactly k = 2 dollars.

Sample Input 1

2
1

Sample Output 1

Explanation 1
George visits the following sequence of n = 2 taxpayers:
1. George will not collect 1 dollar from taxpayer 1 because k =
1 and he refuses to have asum ≡ k at any time.
2. George moves on and collects 2 dollars from taxpayer 2 to
get sum = 0 + 2 = 2.

Sample Input 2

3
3

Sample Output 2

Explanation 2
George must skip some taxpayer because collecting from all
taxpayers will result in a sum ≡ k = 3 when he collects from the
second taxpayer. There are two ways for him to visit all n = 3
taxpayers:
He can collect 1 dollar from taxpayer 1 to get sum = 1. Next,
he can refuse to collect 2 dollars from taxpayer 2 to avoid
having a sum equal to k. Next, he can collect 3 dollars from
taxpayer 3 to get sum = 1 + 3 = 4.
He can refuse to collect 1 dollar from taxpayer 1, meaning
that sum = 0. Next, he can collect 2 dollars from taxpayer 2
to get sum = 0 + 2 = 2. Next, he can collect 3 dollars from
taxpayer 3 to get sum = 2 + 3 = 5.
Because we want the maximum amount of money that George
can collect from his sequentially-numbered taxpayers without
ever having a sum equal to k, we return 5 as our answer.

Question - 8 SCORE: 100 points


Simplifying debts among friends

A group of friends go on a trip together, where they borrow and


lend money to each other all the time. When the trip ends, they
want to know a way of paying off all their debts minimizing the
total amount of money they have to handle.

For example, in the following case:


Alice lends Bob $1
Bob lends Carol $1
Carol lends Alice $2
Alice lends Carol $1
First note that both Alice and Carol lended to each other, so
simplifying gives:
Alice lends Bob $1
Bob lends Carol $1
Carol lends Alice $1
And this can be further simplified: no one owes anything to the
rest!
Note that we intend to minimize the amount of money
transferred, not the amount of transfers needed. Both are not the
same, for example:
Alice transfers Carol $3
Bob transfers Dave $3
Alice transfers Dave $2
and
Alice transfers Dave $5
Bob transfers Carol $3
are both acceptable answers to an instance of this problem,
since both are equivalent and transfer in total $8, the minimum
amount possible.

Input format
Important: input is already parsed by us. The format is only
important if you want to use the ‘Custom input’ option.

The first line contains the amount of friends,N, and the amount
of loans, L. Each friend will be referenced by a number between
0 and N-1 .
Each of the following L lines contains three integers describing a
loan: the friend who lended, the friend who borrowed, and the
amount of money.

Constraints
1 ≤ N ≤ 106
1 ≤ L ≤ 106

Output Format
The function must return a list of transfers to pay off all the
debts, minimizing the amount of money being transferred
among the group.

Sample input 0

3 4
0 1 1
1 2 1
0 2 1
2 0 2

Sample output 0

Sample input 1

4 4
0 2 2
1 2 4
1 3 3
0 3 1

Sample output 1

3
203
213
314

You might also like