Online Election
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
An election records one vote at a time: the i-th vote was cast for candidate persons[i] at time times[i], and times is strictly increasing.
Implement TopVotedCandidate(persons, times) and q(t), which returns the candidate who was leading at time t. Votes cast exactly at time t count.
The leader is the candidate with the most votes so far. If several candidates are tied for the most votes, the leader is the tied candidate who received a vote most recently. Every query satisfies t >= times[0].
Examples
Constraints
- 1 <= persons.length <= 5000
- `times.length == persons.length`, 0 <= times[i] <= 10^9, strictly increasing
- 0 <= persons[i] < persons.length
- `times[0] <= t <= 10^9`
- At most 10^4 calls to `q`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.