/**
 * Exercise:
 * Given two words (word1 and word2) and a frequency map (frequency) containing the count
 * of each character in the words, write a function to find and return a list of common letters
 * between the two words.
 */
fun findCommonLetters(word1: String, word2: String, frequency: MutableMap<Char, Int>): List<Char> {

    val commonLetters = mutableListOf<Char>()
    var i = 0
    while (i < word1.length) {
        val letter = word1[i]
        if (word2.contains(letter) && frequency[letter]!! > 0) {
            commonLetters.add(letter)
            frequency[letter] = frequency[letter]!! - 1
        }
        i++
    }
    return commonLetters
}
/**
 * Exercise:
 * Given two words (word1 and word2) and a frequency map (frequency) containing the count
 * of each character in the words, write a function to find and return a list of common letters
 * between the two words.
 */
fun findCommonLetters(word1: String, word2: String, frequency: MutableMap<Char, Int>): List<Char> {
/**
 * Exercise:
 * Given two words (word1 and word2) and a frequency map (frequency) containing the count
 * of each character in the words, write a function to find and return a list of common letters
 * between the two words.
 */
fun findCommonLetters(word1: String, word2: String, frequency: MutableMap<Char, Int>): List<Char> {

    val commonLetters = mutableListOf<Char>()
    var i = 0
    while (i < word1.length) {
        val letter = word1[i]
        if (word2.contains(letter) && frequency[letter]!! > 0) {
            commonLetters.add(letter)
            frequency[letter] = frequency[letter]!! - 1
        }
        i++
    }
    return commonLetters
}