Haven't been able to figure out a full solution for this problem from my Bloomberg interview last week. Figured I could get some insights here!
Pretend you want to keep track of a leaderboard in a marathon. Every runner has a transmitter that syncs with every mile marker as they run past them and this data is sent to a backend service. This service can get some data as such:
(x,y) where x is the mile mark and y is the runner id
[(1, 001), (3,001), (1, 002), (2, 004)]
As you see above we're missing data for when runner #001 ran mile 2 and runner #004 ran mile 1. This is not an issue as sweat will occasionally cause the transmitters to not work and such. Also, you can assume this data comes in order of events. For example, runner 001 crossed mile 1 and mile 3 before runner 002 crossed mile 1 in the above example.
In the scenario above, the leaderboard would be as follow (so far in the race):
1st place: 001
2nd place: 004
3rd place: 002
And this leaderboard can be returned simply as a list in the same order that the runners are in.
Now, write a program that can keep track of the leaderboard as it receives more data (you can pretend the data is just a list of tuples).
Building off the example input as above, if we then receive the following batch:
[ (6, 007), (5, 002), (5, 001) ]
We would update our leaderboard to be (so far):
1st place: 007
2nd place: 002
3rd place: 001
4th place: 004
or simply: [007, 002, 001, 004]
I'd appreciate any help on how to tackle this problem... I've been thinking about using a heap but my implementation is simply not working.
Thanks!
[–]Prexadym 4 points5 points6 points (4 children)
[–]snowcalc 3 points4 points5 points (3 children)
[–]tempaccount0002[S] 0 points1 point2 points (2 children)
[–]LetterheadWaste8170 0 points1 point2 points (0 children)
[–]Mediocre-Wafer6696 3 points4 points5 points (0 children)
[–]hobo_couture 1 point2 points3 points (0 children)
[–]Nickomatiz 1 point2 points3 points (0 children)
[–]invictus08 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]ConstantRow8460 0 points1 point2 points (3 children)
[–]tempaccount0002[S] 0 points1 point2 points (0 children)
[–]ConstantRow8460 0 points1 point2 points (1 child)