/**
 * Given a list of articles, find the common words that appear in each article.
 *
 * @param articles A list of strings representing the articles.
 * @return A list of strings containing the common words across all articles.
 */
fun findCommonWords(articles: List<String>): List<String> {

    var commonWords = mutableListOf<String>()

    // Loop through the articles
    for ((index, article) in articles.withIndex()) {
        // Split the article into individual words
        val words = article.split(" ")

        // If it's the first article, initialize the common words list
        if (index == 0) {
            commonWords.addAll(words)
        } else {
            // Create a new list to store the common words for the current article
            val currentCommonWords = mutableListOf<String>()

            // Loop through the words in the current article
            for (word in words) {
                // Check if the word is already in the common words list and not in the currentCommonWords list
                if (word in commonWords && word !in currentCommonWords) {
                    currentCommonWords.add(word)
                }
            }

            // Update the common words list with the new common words found in the current article
            commonWords = currentCommonWords.toMutableList()
        }
    }

    return commonWords
}
/**
 * Given a list of articles, find the common words that appear in each article.
 *
 * @param articles A list of strings representing the articles.
 * @return A list of strings containing the common words across all articles.
 */
fun findCommonWords(articles: List<String>): List<String> {
/**
 * Given a list of articles, find the common words that appear in each article.
 *
 * @param articles A list of strings representing the articles.
 * @return A list of strings containing the common words across all articles.
 */
fun findCommonWords(articles: List<String>): List<String> {

    var commonWords = mutableListOf<String>()

    // Loop through the articles
    for ((index, article) in articles.withIndex()) {
        // Split the article into individual words
        val words = article.split(" ")

        // If it's the first article, initialize the common words list
        if (index == 0) {
            commonWords.addAll(words)
        } else {
            // Create a new list to store the common words for the current article
            val currentCommonWords = mutableListOf<String>()

            // Loop through the words in the current article
            for (word in words) {
                // Check if the word is already in the common words list and not in the currentCommonWords list
                if (word in commonWords && word !in currentCommonWords) {
                    currentCommonWords.add(word)
                }
            }

            // Update the common words list with the new common words found in the current article
            commonWords = currentCommonWords.toMutableList()
        }
    }

    return commonWords
}