/**
 * Given a string and a number, this function returns the vowels present at the specified indices.
 *
 * @param string The input string.
 * @param n The number of indices to return.
 * @return A list of vowels at the specified indices in the input string.
 *
 * Example:
 * findVowels("hello world", 3) returns ['e', 'o', 'o']
 */
fun findVowels(string: String, n: Int): List<Char> {

    val vowels = listOf('a', 'e', 'i', 'o', 'u')
    val indices = string.mapIndexedNotNull { index, char -> if (char.toLowerCase() in vowels) index else null }
        .sortedDescending()

    val result = mutableListOf<Char>()
    var count = 0
    var i = 0

    while (count < n && i < indices.size) {
        val index = indices[i]

        // If the current index is within the string length, add the vowel to the result
        if (index < string.length) {
            result.add(string[index])
            count++
        }

        i++
    }

    return result
}
/**
 * Given a string and a number, this function returns the vowels present at the specified indices.
 *
 * @param string The input string.
 * @param n The number of indices to return.
 * @return A list of vowels at the specified indices in the input string.
 *
 * Example:
 * findVowels("hello world", 3) returns ['e', 'o', 'o']
 */
fun findVowels(string: String, n: Int): List<Char> {
/**
 * Given a string and a number, this function returns the vowels present at the specified indices.
 *
 * @param string The input string.
 * @param n The number of indices to return.
 * @return A list of vowels at the specified indices in the input string.
 *
 * Example:
 * findVowels("hello world", 3) returns ['e', 'o', 'o']
 */
fun findVowels(string: String, n: Int): List<Char> {

    val vowels = listOf('a', 'e', 'i', 'o', 'u')
    val indices = string.mapIndexedNotNull { index, char -> if (char.toLowerCase() in vowels) index else null }
        .sortedDescending()

    val result = mutableListOf<Char>()
    var count = 0
    var i = 0

    while (count < n && i < indices.size) {
        val index = indices[i]

        // If the current index is within the string length, add the vowel to the result
        if (index < string.length) {
            result.add(string[index])
            count++
        }

        i++
    }

    return result
}