Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.1 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a19b1062d1b153d8ac76d72 Challenge 324: Duplicate Character Count 29 challenge-324

--description--

Given two strings, return a count of characters from the second string that can be found in the first.

  • Duplicate characters in the second string are counted separately.

--hints--

duplicate_character_count("aloha", "hei") should return 1.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(duplicate_character_count("aloha", "hei"), 1)`)
}})

duplicate_character_count("jambo", "bonjour") should return 4.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(duplicate_character_count("jambo", "bonjour"), 4)`)
}})

duplicate_character_count("hello", "hola") should return 3.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(duplicate_character_count("hello", "hola"), 3)`)
}})

duplicate_character_count("ola", "hej") should return 0.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(duplicate_character_count("ola", "hej"), 0)`)
}})

duplicate_character_count("ciao", "konnichiwa") should return 5.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(duplicate_character_count("ciao", "konnichiwa"), 5)`)
}})

duplicate_character_count("merhaba", "xin chao") should return 2.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(duplicate_character_count("merhaba", "xin chao"), 2)`)
}})

duplicate_character_count("hello world", "hello to everyone around the world") should return 26.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(duplicate_character_count("hello world", "hello to everyone around the world"), 26)`)
}})

--seed--

--seed-contents--

def duplicate_character_count(str1, str2):

    return str1

--solutions--

def duplicate_character_count(str1, str2):
    return sum(1 for char in str2 if char in str1)