/**
 * Given an article and a list of words, find the common words that appear in the article.
 *
 * @param article The full text of the article.
 * @param wordList A list of words to compare with the article.
 * @return A list of common words found in the article.
 */
fun findCommonWords(article: String, wordList: List<String>): List<String> {

    // Convert the article into a list of lowercase words
    val articleWords = article.toLowerCase().split(" ")

    // Initialize an empty map to store the word frequencies
    val wordFreq = mutableMapOf<String, Int>()

    // Count the frequency of each word in the article
    for (word in articleWords) {
        wordFreq[word] = wordFreq.getOrDefault(word, 0) + 1
    }

    // Initialize an empty list to store the common words
    val commonWords = mutableListOf<String>()

    // Find the common words between the article and the given word list
    for (word in wordList) {
        if (wordFreq.getOrDefault(word.toLowerCase(), 0) > 0) {
            commonWords.add(word)
        }
    }

    return commonWords
}
/**
 * Given an article and a list of words, find the common words that appear in the article.
 *
 * @param article The full text of the article.
 * @param wordList A list of words to compare with the article.
 * @return A list of common words found in the article.
 */
fun findCommonWords(article: String, wordList: List<String>): List<String> {
/**
 * Given an article and a list of words, find the common words that appear in the article.
 *
 * @param article The full text of the article.
 * @param wordList A list of words to compare with the article.
 * @return A list of common words found in the article.
 */
fun findCommonWords(article: String, wordList: List<String>): List<String> {

    // Convert the article into a list of lowercase words
    val articleWords = article.toLowerCase().split(" ")

    // Initialize an empty map to store the word frequencies
    val wordFreq = mutableMapOf<String, Int>()

    // Count the frequency of each word in the article
    for (word in articleWords) {
        wordFreq[word] = wordFreq.getOrDefault(word, 0) + 1
    }

    // Initialize an empty list to store the common words
    val commonWords = mutableListOf<String>()

    // Find the common words between the article and the given word list
    for (word in wordList) {
        if (wordFreq.getOrDefault(word.toLowerCase(), 0) > 0) {
            commonWords.add(word)
        }
    }

    return commonWords
}