Pergunta de entrevista da empresa Paycom

Return the character has the highest frequency in a string.

Resposta da entrevista

Sigiloso

31 de ago. de 2022

function mostRepeatedString(s) { const occurances = new Array(128).fill(0); let maxChar = ''; let max = -1; s.split("").forEach((c) => { const code = c.charCodeAt(0); occurances[code]++; if (occurances[code] > max) { max = occurances[code]; maxChar = c; } }); return maxChar; } // Time: O(n), space O(1);