Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
O(n) solution in Clear category for [old] The Most Wanted Letter by Sim0000
"use strict";
function mostWanted(data) {
let count = {};
let maxc;
let maxv = 0;
for(let c of data.toLowerCase()){
if('a' <= c && c <= 'z'){
count[c] = (count[c] ? count[c] : 0) + 1;
if(count[c] > maxv || (count[c] == maxv && c < maxc)){
maxc = c;
maxv = count[c];
}
}
}
return maxc;
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(mostWanted("Hello World!"), "l", "1st example");
assert.equal(mostWanted("How do you do?"), "o", "2nd example");
assert.equal(mostWanted("One"), "e", "3rd example");
assert.equal(mostWanted("Oops!"), "o", "4th example");
assert.equal(mostWanted("AAaooo!!!!"), "a", "Letters");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Feb. 21, 2017