As reported: Amazon SDE 1 fixed-term role (Bengaluru, Aug 2025), interview 1: Online Election, asked exactly as on LeetCode, plus Leadership Principle questions. An optimal solution was expected.
You are given two arrays persons and times: the i-th vote was cast for persons[i] at time times[i]. Implement TopVotedCandidate:
TopVotedCandidate(persons, times)— initialise with the votes.q(t)— return the person leading at timet. Votes cast at timetcount. In a tie, the most recent vote among the tied candidates wins.
This is LeetCode 911 — Online Election.
Example
persons = [0,1,1,0,0,1,0], times = [0,5,10,15,20,25,30]
q(3) -> 0, q(12) -> 1, q(25) -> 1, q(15) -> 0, q(24) -> 0, q(8) -> 1
At t = 15 the votes are 0,1,1,0 — a 2–2 tie — and person 0 voted most recently, so 0 leads.
Constraints: 1 ≤ persons.length ≤ 5000; times is strictly increasing; times[0] ≤ t ≤ 10⁹; at most 10⁴ calls to q.
Code runner format: two lines, LeetCode's class format: the method names as a JSON array (starting with "TopVotedCandidate"), then their arguments as a JSON array of arrays. The harness prints the results as a JSON array (null for the constructor).