/**
 * Given a dictionary and a string, the function finds the characters that are present in all the values of the
 * dictionary and also in the given string. It returns a list containing these common characters.
 *
 * @param dictionary A dictionary where the values are strings.
 * @param string A string in which characters need to be found.
 * @return A list containing the common characters found in the values of the dictionary and the given string.
 *
 * Examples:
 * dictionary = mapOf("word1" to "hello", "word2" to "world", "word3" to "python")
 * string = "program"
 * findCommonChars(dictionary, string) // Output: ['o', 'r']
 *
 * dictionary = mapOf("word1" to "apple", "word2" to "berry", "word3" to "cherry")
 * string = "champaign"
 * findCommonChars(dictionary, string) // Output: ['a']
 */
fun findCommonChars(dictionary: Map<String, String>, string: String): List<Char> {

    val commonChars = mutableListOf<Char>()
    if (dictionary.isEmpty()) {
        return commonChars
    }

    // Initialize using the first word in the dictionary
    val firstWordChars = dictionary.values.first().toSet()
    commonChars.addAll(firstWordChars)

    // Find common characters amongst all
    for (word in dictionary.values) {
        commonChars.retainAll(word.toSet())
    }

    // Find common characters with the given string
    commonChars.retainAll(string.toSet())

    return commonChars
}
/**
 * Given a dictionary and a string, the function finds the characters that are present in all the values of the
 * dictionary and also in the given string. It returns a list containing these common characters.
 *
 * @param dictionary A dictionary where the values are strings.
 * @param string A string in which characters need to be found.
 * @return A list containing the common characters found in the values of the dictionary and the given string.
 *
 * Examples:
 * dictionary = mapOf("word1" to "hello", "word2" to "world", "word3" to "python")
 * string = "program"
 * findCommonChars(dictionary, string) // Output: ['o', 'r']
 *
 * dictionary = mapOf("word1" to "apple", "word2" to "berry", "word3" to "cherry")
 * string = "champaign"
 * findCommonChars(dictionary, string) // Output: ['a']
 */
fun findCommonChars(dictionary: Map<String, String>, string: String): List<Char> {
/**
 * Given a dictionary and a string, the function finds the characters that are present in all the values of the
 * dictionary and also in the given string. It returns a list containing these common characters.
 *
 * @param dictionary A dictionary where the values are strings.
 * @param string A string in which characters need to be found.
 * @return A list containing the common characters found in the values of the dictionary and the given string.
 *
 * Examples:
 * dictionary = mapOf("word1" to "hello", "word2" to "world", "word3" to "python")
 * string = "program"
 * findCommonChars(dictionary, string) // Output: ['o', 'r']
 *
 * dictionary = mapOf("word1" to "apple", "word2" to "berry", "word3" to "cherry")
 * string = "champaign"
 * findCommonChars(dictionary, string) // Output: ['a']
 */
fun findCommonChars(dictionary: Map<String, String>, string: String): List<Char> {

    val commonChars = mutableListOf<Char>()
    if (dictionary.isEmpty()) {
        return commonChars
    }

    // Initialize using the first word in the dictionary
    val firstWordChars = dictionary.values.first().toSet()
    commonChars.addAll(firstWordChars)

    // Find common characters amongst all
    for (word in dictionary.values) {
        commonChars.retainAll(word.toSet())
    }

    // Find common characters with the given string
    commonChars.retainAll(string.toSet())

    return commonChars
}