/**
 * Given a dictionary of words and their frequencies, find the word with the highest frequency
 * and return its index.
 *
 * @param words A dictionary with words as keys and their frequencies as values.
 * @return Index of the word with the highest frequency.
 *
 * Example:
 * val words = mapOf("apple" to 10, "banana" to 24, "cherry" to 13, "durian" to 5)
 * findItem(words) // Output: 1
 */
fun findItem(words: Map<String, Int>): Int {

    var highestFreq = 0
    var highestFreqIdx = 0
    var index = 0

    while (index < words.size) {
        val word = words.keys.toList()[index] // Accessing dictionary items
        val freq = words[word] ?: 0

        if (freq > highestFreq) {
            highestFreq = freq
            highestFreqIdx = index
        }

        index++
    }

    return highestFreqIdx
}
/**
 * Given a dictionary of words and their frequencies, find the word with the highest frequency
 * and return its index.
 *
 * @param words A dictionary with words as keys and their frequencies as values.
 * @return Index of the word with the highest frequency.
 *
 * Example:
 * val words = mapOf("apple" to 10, "banana" to 24, "cherry" to 13, "durian" to 5)
 * findItem(words) // Output: 1
 */
fun findItem(words: Map<String, Int>): Int {
/**
 * Given a dictionary of words and their frequencies, find the word with the highest frequency
 * and return its index.
 *
 * @param words A dictionary with words as keys and their frequencies as values.
 * @return Index of the word with the highest frequency.
 *
 * Example:
 * val words = mapOf("apple" to 10, "banana" to 24, "cherry" to 13, "durian" to 5)
 * findItem(words) // Output: 1
 */
fun findItem(words: Map<String, Int>): Int {

    var highestFreq = 0
    var highestFreqIdx = 0
    var index = 0

    while (index < words.size) {
        val word = words.keys.toList()[index] // Accessing dictionary items
        val freq = words[word] ?: 0

        if (freq > highestFreq) {
            highestFreq = freq
            highestFreqIdx = index
        }

        index++
    }

    return highestFreqIdx
}