Shopee Programming Contest #2
Shopee Programming Contest #2
The competition starts from 1pm (GMT+7) / 2pm (GMT+8) to 4:15pm (GMT+7) / 5:15pm
(GMT+8). The countdown will begin at 1pm (GMT+7) / 2PM (GMT+8) and you will have 3
hours 15min to submit your codes.
Duration: 3 Hours 15 Minutes (Additional 15 minutes is given for your team to familiarise with
the competition platform)
1
Highest Mountain
Problem Statement
Victor is assigned a task for planning quarterly team outings in Shopee. He is trying to
organize an outdoor activity to climb the highest mountain among a mountain range.
However, it is difficult to tell which mountain is the highest in the mountain range from a
distance. Help Victor to identify the highest mountain given the height of the mountains.
Input
Subsequent N sets will have length L and a series of numbers separated by space
representing the height (H)
Output
Integer specifying the height (H) of the highest mountain and index (I) of the peak. If
there are multiple mountains with the same height, return the leftmost mountain.
If the height or index is not available, return -1. Return the result for each case with
format “Case #{N}: H I”
2
Sample Explanation
1 2 3 2 3 4 2 3 2 5
3 has a way to enter from the ground while 4 and 5 doesn’t.
The highest mountain will be "1 2 3" with the height of 3 because a mountain can only
be either increase or decrease consistently by 1 and not both. When it increase from 1
to 3, it cannot decrease to 2 again.
3 2 3 2 3 4 3 2 1 4
4 has a way to enter from the ground and it is decreasing consistently by 1.
23456
There is no way to enter from the ground.
1 2 4 5
The mountain is unable to jump from 2 to 4.
Sample Input
10
1232342325
10
3232343214
5
11111
10
10 9 8 7 6 5 4 3 2 1
1
5
1
1
3
Sample Output
Case #1: 3 2
Case #2: 4 5
Case #3: 1 0
Case #4: 10 0
Case #5: -1 -1
Case #6: 1 0
4
Shopee Logistics
Problem Statement
We have a lot of interesting tasks at Shopee. One of them is a logistics problem. In this
problem we need to deliver goods from the hub to the final customer. But before that we
can move goods between the hubs. Shopee has a giant network of hubs but in this task
will be used the network with N hubs and N - 1 routes between hubs. Each hub is
reachable from any other hub.
In this task we are asking you to find the second longest path in the Shopee network.
Don’t need to output the path! We need only the length!
Input
Input starts with an integer N (5 ≤ N ≤ 105), denoting the number of hubs. Next N - 1
lines contain three values: two hubs and the route length between them. Li ≤ 105.
Output
Sample Explanation
The longest path will be 1->2->5: (8). The second longest path will be 1->2->4. (7)
Sample Input
5
125
231
242
253
5
Sample Output
7
6
Connectivity
Problem Statement
In Shopee Data Center, there are many switches and some of the switches are
interconnected to form a network. Sometimes, we add a new connection to the network
and if we find that there is some issue, we may remove the last added connections. You
will need to solve a similar problem.
You are given an empty network with N switches (numbered 1 to N) and no connections
between switches. You will also face Q scenarios in chronological order. Each scenario
can be any of the following:
PUSH u v : You have to add a new connection between switches u and v. (u ≠ v, 1 <=
u, v <= N). Note that there can be multiple connections between the same pair of
switches.
POP : From all the connections currently present in the network, remove the one that
was added most recently. There will be at least one connection in the network when this
scenario is given.
Also, after performing the operation in each scenario, print the number of connected
components formed by the switches in this network.
Input
The first line of test case begins with integer Q (1 <= Q <= 5 * 105) and N (1 <= N <= 5 *
105) indicating the number of scenarions and number of switches in the network. Next,
Q lines will each contain a scenario as described above.
Output
For each query, you will need to print the answer in a separate line.
7
Sample Input
12 5
PUSH 1 2
PUSH 2 3
PUSH 1 4
POP
PUSH 1 3
PUSH 4 5
PUSH 1 4
POP
POP
POP
POP
POP
Sample Output
4
3
2
3
3
2
1
2
3
3
4
5
8
Wifi Network
Problem Statement
As we all know Shopee is one of the fastest-growing e-commerce in the world. Shopee
has a large number of engineers to develop and maintain the platform. So it's expected
it’s internal office network is very complex and only one master WiFi network hub has
already failed to support the network stability and bandwidth. Now Shopee has decided
to get master WiFi network hubs from two different companies namely GeoFi and AirFi.
However now there is another big problem, these two networking device manufacturing
companies have a long history of rivalry. They developed their network technology in
such a way that these two networks cancel each other. Meaning, if an engineer is inside
the network range of both GeoFi and AirFi network hubs, he/she will not get any signal
from either of these two network hubs (see the picture).
As installing networking devices without very complex calculation can bring networking
blackout at different locations on the office floor, shopee IT-center decided to install only
one GeoFi network hub on the office floor. The same rule goes for the AirFi network
hub. Each hub has a range R and they cover a circular area of radius R centering the
position of the network hub. Shopee IT-center wishes every engineer should get the
WiFi signal from one of the two new network hubs. Now Shopee IT-center wants your
help to get the answer to the following question. Given the coordinates of each of the
engineers, coordinates of the GeoFi network hub Cg and AirFi network hub Ca, the
range of these network hubs Rg(GeoFi) and Ra(AirFi) can you find the number of
engineers that will not get any network services?
9
In the picture above the two points (a,b) in the intersected area do not get any WiFi
signal. Also the three points(c,d,e) outside the area of the circles do not have any WiFi
signal.
Input
There will be only one test case. The test case begins with an integer N (1 ≤ N ≤ 105),
the number of engineers in the office.
Each of the next N lines will have two integers x, y (0 ≤ x,y ≤ 108) representing the
coordinates of the engineers.
The next line contains four integers Xg, Yg representing Cg, and Xa, Ya representing
Ca.
The next line contains an integer number Q (1 ≤ Q ≤ 105), representing the number of
queries. Each of the next Q lines will have two integers Rg, Ra (0 ≤ Rg, Ra ≤ 108).
Output
For each query (given value of Rg, Ra), print the number of engineers that will not get
any WiFi signal.
10
Sample Input
11
23
36
55
6 10
97
85
94
11 3
12 6
11 12
14 10
6 7 10 5
5
43
33
93
83
32
Sample Output
5
6
5
6
7
11
Number Tree
Problem Statement
Your colleague Alice came up with an interesting puzzle, and discussed with you to find
out the solution together.
The puzzle is in the form of an undirected tree graph with N nodes, with the following
characteristics:
● Each nodes are given a number from 1 to N
● Each edges have a single digit integer written in it
The value of a path was defined as the concatenation of the number written in the
edges of the path, starting from the node with lower number. For example, in the
example above, the value from node 2 to node 3 is 35, and value from node 2 to node 4
is 356. Then, the puzzle is calculating the sum of value from each possible path in the
tree.
12
Input
The first line contains 1 integer N (1 ≤ N ≤ 100,000), denoting the number of nodes.
The next N-1 line contains Ui Vi Ci (1 ≤ Ui, Vi ≤ N, 0 ≤ Ci ≤ 9), denoting an edge
between node Ui and node Vi which has number Ci written in it. It is guaranteed that the
given graph is a tree graph.
Output
One line containing a single integer, the answer of this puzzle. Since this number can
be very large, output its value modulo 109+7.
Sample Explanation
Sample Input
4
123
135
346
Sample Output
461
13