Every lighthouse along a rocky coastline keeps a rolling log of how passing ships react to its beam. Each log entry records one ship's encounter with one particular lighthouse, classified as exactly one of three outcomes: the ship Signaled back to acknowledge the beam, the ship Sighted the beam but sent no signal back, or the ship Missed the beam entirely (it never noticed the light was there).
The harbor authority wants a per-lighthouse acknowledgment rate: among only the encounters where the beam was actually noticed (Signaled or Sighted), what fraction resulted in a signal back? Encounters where the beam was Missed are excluded entirely -- they neither count as a notice nor drag the rate down. For a lighthouse whose beam was never noticed at all (so the denominator would be zero), its acknowledgment rate is defined to be exactly 0.
Given the full log, compute the acknowledgment rate for every distinct lighthouse that appears in it.
n, the number of log entries.n lines contains an integer id (the lighthouse identifier) followed by a space and a string action, where action is exactly one of Signaled, Sighted, or Missed.id that appears in the log, each containing the id followed by a space and its acknowledgment rate as a percentage rounded to exactly two decimal places (e.g. 66.67).100 * Signaled / (Signaled + Sighted), or 0.00 if Signaled + Sighted is 0 for that lighthouse.1 <= n <= 10^51 <= id <= 10^4action is one of "Signaled", "Sighted", "Missed"Example 1
Input
5 1 Signaled 1 Sighted 1 Missed 2 Sighted 3 Missed
Expected
1 50.00 2 0.00 3 0.00
Explanation
Lighthouse 1 has 1 Signaled and 1 Sighted (its 1 Missed is excluded), so its rate is 100*1/2 = 50.00. Lighthouse 2 has 0 Signaled and 1 Sighted, so its rate is 0.00. Lighthouse 3 has only a Missed encounter, so its denominator is 0 and its rate is defined as 0.00. Sorted by rate descending then id ascending: 1 (50.00), then 2 and 3 tie at 0.00 and are ordered by id, giving 2 before 3.
Example 2
Input
3 7 Missed 7 Missed 9 Missed
Expected
7 0.00 9 0.00
Explanation
Both lighthouse 7 and lighthouse 9 only ever have their beams Missed, so each has Signaled + Sighted = 0 and their rate is defined as 0.00. They tie, so they are ordered by id ascending: 7 then 9.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →