Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save optyler/79b33c629bb74f563d7d to your computer and use it in GitHub Desktop.
Save optyler/79b33c629bb74f563d7d to your computer and use it in GitHub Desktop.
Codinggame - Puzzles
var N = +readline();
var ROOT = {}; // All tree node with all numbers
var max = 0; // number of new keys in trees
for (let i = 0, CR; i < N; i++) {
CR = ROOT; // Current sub root elements with fragments of numbers, we always starts
var s = readline().split('');
for(let j=0, len=s.length; j < len; j++) {
if (! CR.hasOwnProperty(s[j])) { // if the current branch have not the current number as a key, add it and increment counter
CR[s[j]] = {};
++max;
}
CR = CR[s[j]];
}
}
print(max); // The number of elements (referencing a number) stored in the structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment