/**
 * Given a text and a word, find the indices of all occurrences of the word in the string and return the indices in reverse order.
 * Ignore case sensitivity.
 *
 * @param text The input text.
 * @param word The word to search for in the text.
 * @return A list of indices representing the reverse order of occurrences of the word in the text.
 *
 * Example:
 * exitLoop("Hello, hello, hello!", "hello") -> [16, 9, 2]
 */
fun exitLoop(text: String, word: String): List<Int> {

    val indices = mutableListOf<Int>()
    var index = text.length - 1

    while (index >= 0) {
        if (text.substring(index, index + word.length).equals(word, ignoreCase = true)) {
            indices.add(index)
            index -= word.length
        } else {
            index--
        }
    }

    return indices.reversed()
}
/**
 * Given a text and a word, find the indices of all occurrences of the word in the string and return the indices in reverse order.
 * Ignore case sensitivity.
 *
 * @param text The input text.
 * @param word The word to search for in the text.
 * @return A list of indices representing the reverse order of occurrences of the word in the text.
 *
 * Example:
 * exitLoop("Hello, hello, hello!", "hello") -> [16, 9, 2]
 */
fun exitLoop(text: String, word: String): List<Int> {
/**
 * Given a text and a word, find the indices of all occurrences of the word in the string and return the indices in reverse order.
 * Ignore case sensitivity.
 *
 * @param text The input text.
 * @param word The word to search for in the text.
 * @return A list of indices representing the reverse order of occurrences of the word in the text.
 *
 * Example:
 * exitLoop("Hello, hello, hello!", "hello") -> [16, 9, 2]
 */
fun exitLoop(text: String, word: String): List<Int> {

    val indices = mutableListOf<Int>()
    var index = text.length - 1

    while (index >= 0) {
        if (text.substring(index, index + word.length).equals(word, ignoreCase = true)) {
            indices.add(index)
            index -= word.length
        } else {
            index--
        }
    }

    return indices.reversed()
}