1
class TopVotedCandidate:3
def __init__(self, persons: List[int], times: List[int]):4
counter = defaultdict(int)6
mostVotePersons = [0] * len(8
) # mostVotePersons[i] is the most vote person at times[i]9
largestVote = -1 # keep largest vote person index10
for i in range(len(persons)):11
counter[persons[i]] += 112
if largestVote == -1 or counter[persons[i]] >= counter[largestVote]:13
largestVote = persons[i]14
mostVotePersons[i] = largestVote17
self.mostVotePersons = mostVotePersons19
def q(self, t: int) -> int:21
bisect_right(self.times, t) - 122
) # binary search on times to find the most recent time before t23
return self.mostVotePersons[idx]