Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-209

Phoneme Count

Problem

Count phonemes by greedily matching the longest inventory symbol at each position of word.

Symbols are checked longest-first with alphabetical tie-breaking; unknown characters are skipped. An empty inventory gives 0.

Hint

Sort by descending length so digraphs win over single letters.

Test cases

case 1
in: ["cat",["c","a","t"]]
expected: 3
case 2
in: ["ship",["sh","i","p"]]
expected: 3
case 3
in: ["chch",["ch"]]
expected: 2
case 4
in: ["xyz",[]]
expected: 0
case 5
in: ["abc",["ab","c"]]
expected: 2
Starter codePython
def phoneme_count(word, inventory):
    # Your code here
    pass

5 test cases · run your code against them in the editor