/**
 * This exercise aims to test your understanding of list methods and string slicing.
 * Write a function that takes in a keyword and a text, and returns a list with the indices of all occurrences
 * of the keyword in the text.
 *
 * @param keyword A string representing the keyword to search for.
 * @param text A string representing the text to search within.
 * @return A list containing the indices of all occurrences of the keyword in the text.
 *
 * Example:
 * findKeywordOccurrences("apple", "I have an apple and an apple tree with many apples.")
 * Output: [7, 19, 40]
 */
fun findKeywordOccurrences(keyword: String, text: String): List<Int> {

    val indices = mutableListOf<Int>()
    var start = 0
    while (start < text.length) {
        val index = text.indexOf(keyword, start)
        if (index == -1) {
            return indices
        }
        indices.add(index)
        start = index + 1
    }
    return indices
}
/**
 * This exercise aims to test your understanding of list methods and string slicing.
 * Write a function that takes in a keyword and a text, and returns a list with the indices of all occurrences
 * of the keyword in the text.
 *
 * @param keyword A string representing the keyword to search for.
 * @param text A string representing the text to search within.
 * @return A list containing the indices of all occurrences of the keyword in the text.
 *
 * Example:
 * findKeywordOccurrences("apple", "I have an apple and an apple tree with many apples.")
 * Output: [7, 19, 40]
 */
fun findKeywordOccurrences(keyword: String, text: String): List<Int> {
/**
 * This exercise aims to test your understanding of list methods and string slicing.
 * Write a function that takes in a keyword and a text, and returns a list with the indices of all occurrences
 * of the keyword in the text.
 *
 * @param keyword A string representing the keyword to search for.
 * @param text A string representing the text to search within.
 * @return A list containing the indices of all occurrences of the keyword in the text.
 *
 * Example:
 * findKeywordOccurrences("apple", "I have an apple and an apple tree with many apples.")
 * Output: [7, 19, 40]
 */
fun findKeywordOccurrences(keyword: String, text: String): List<Int> {

    val indices = mutableListOf<Int>()
    var start = 0
    while (start < text.length) {
        val index = text.indexOf(keyword, start)
        if (index == -1) {
            return indices
        }
        indices.add(index)
        start = index + 1
    }
    return indices
}