-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathA.js
More file actions
26 lines (24 loc) · 715 Bytes
/
A.js
File metadata and controls
26 lines (24 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
KickStart 2017
Practice Round
Problem A: Country Leader
Both solved
*/
const fs= require('fs');
const input= fs.readFileSync(0,'utf8').trim().split(/\d+\s+/).filter(Boolean);
console.log(input.map((e,i)=>`Case #${i+1}: ${solve(e)}`).join('\n'));
function solve(strOfNames) {
const allNames= strOfNames.split('\n');
const longestNames= new Set;
let max= 0;
allNames.forEach((name)=>{
const uniqueChars= new Set(name);
uniqueChars.delete(' ');
if(uniqueChars.size>max) {
max= uniqueChars.size;
longestNames.clear();
}
if (uniqueChars.size===max) longestNames.add(name);
});
return [...longestNames].sort()[0];
}