Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-100

Character Coverage

Problem

Return the fraction of characters in text that appear in the allowed character list.

Count every occurrence, so repeated characters weigh equally, and return 0.0 for empty text.

Hint

Put allowed in a set, then count matching characters over the full length.

Test cases

case 1
in: ["abc",["a","b"]]
expected: 0.6666666666666666
case 2
in: ["abc",["a","b","c"]]
expected: 1
case 3
in: ["",["a"]]
expected: 0
case 4
in: ["😀",["😀"]]
expected: 1
Starter codePython
def character_coverage(text, allowed):
    # Your code here
    pass

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