transport can be shortened to t7t, tr2sp3, 9, or left as transport, while t25t is not allowed: the replaced stretches "ran" and "sport" touch each other.
The length of a shorthand is the number of letters kept plus the number of replaced stretches: t7t has length 3, tr2sp3 has length 6. A shorthand fits a word if it can be produced from that word in the way described.
You are given a word word and a list vocabulary. Find a shorthand of word of the smallest length that fits none of the vocabulary words.
If several shortest ones exist, return the one that hides letters as far left as possible: compare two candidates position by position from the left, and at the first difference pick the one whose letter at that position is hidden inside a number.word='cat', vocabulary=['cut'] → '1a1'
"3", "c2" and "2t" also fit "cut". Among shorthands of length 3, the tie rule puts "1a1" first: it hides the first letter, and "cut" does not fit it because it has u where the a is.
word='apple', vocabulary=[] → '5'
The vocabulary is empty, so the shortest shorthand of all, a single number, will do.
word='plan', vocabulary=['plum', 'clan'] → 'p2n'
Every shorthand of length 2 fits one of the vocabulary words. Of the length-3 shorthands only "p2n" is free of clashes: "plum" ends in m and "clan" starts with c.
word.length ≤ 21vocabulary.length ≤ 1000word, then k · 2^word.length ≤ 2²¹vocabulary[i].length ≤ 100word is not in the vocabularyword='cat', vocabulary=['cut']
'1a1'
Run checks the first 3 tests in your browser. Submit checks all 43 tests on the server, hidden ones included.