1
var TopVotedCandidate = function (persons, times) {3
this.len = times.length;4
this.votes = new Array(this.len).fill(0);6
let max = 0; // max votes received by any single candidate so far.9
this.leaders = persons.map((person, i) => {12
if (this.votes[person] >= max) {13
max = this.votes[person];21
TopVotedCandidate.prototype.q = function (t) {23
let right = this.len - 1;25
while (left <= right) {26
const mid = left + Math.floor((right - left) / 2);28
if (this.times[mid] === t) return this.leaders[mid];29
else if (this.times[mid] < t) left = mid + 1;33
return this.leaders[right];