1
class TopVotedCandidate:
2

3
def __init__(self, persons: List[int], times: List[int]):
4
counter = defaultdict(int)
5

6
mostVotePersons = [0] * len(
7
persons
8
) # mostVotePersons[i] is the most vote person at times[i]
9
largestVote = -1 # keep largest vote person index
10
for i in range(len(persons)):
11
counter[persons[i]] += 1
12
if largestVote == -1 or counter[persons[i]] >= counter[largestVote]:
13
largestVote = persons[i]
14
mostVotePersons[i] = largestVote
15

16
self.times = times
17
self.mostVotePersons = mostVotePersons
18

19
def q(self, t: int) -> int:
20
idx = (
21
bisect_right(self.times, t) - 1
22
) # binary search on times to find the most recent time before t
23
return self.mostVotePersons[idx]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0