/**
 * Given a string 'sequence' and a string 'subsequence', write a function that finds and returns the
 * indices at which the 'subsequence' occurs within the 'sequence', using loops only.
 *
 * @param sequence The main string to search for occurrences of the 'subsequence'.
 * @param subsequence The string that needs to be found within the 'sequence'.
 * @return A list containing the indices at which the 'subsequence' occurs within the 'sequence'.
 *
 * Note:
 * - The function should be case-sensitive.
 *
 * Example:
 * findSequenceOccurrences("banana", "an") // [1, 3]
 * findSequenceOccurrences("Abracadabra", "bra") // [1, 8]
 */
fun findSequenceOccurrences(sequence: String, subsequence: String): List<Int> {

    val occurrences = mutableListOf<Int>() // Empty list to store the indices of subsequence occurrences

    // Loop through the sequence to find all occurrences of the subsequence
    for (i in 0 until sequence.length) {
        if (sequence.substring(i, i + subsequence.length) == subsequence) {
            occurrences.add(i)
        }
    }

    return occurrences
}
/**
 * Given a string 'sequence' and a string 'subsequence', write a function that finds and returns the
 * indices at which the 'subsequence' occurs within the 'sequence', using loops only.
 *
 * @param sequence The main string to search for occurrences of the 'subsequence'.
 * @param subsequence The string that needs to be found within the 'sequence'.
 * @return A list containing the indices at which the 'subsequence' occurs within the 'sequence'.
 *
 * Note:
 * - The function should be case-sensitive.
 *
 * Example:
 * findSequenceOccurrences("banana", "an") // [1, 3]
 * findSequenceOccurrences("Abracadabra", "bra") // [1, 8]
 */
fun findSequenceOccurrences(sequence: String, subsequence: String): List<Int> {
/**
 * Given a string 'sequence' and a string 'subsequence', write a function that finds and returns the
 * indices at which the 'subsequence' occurs within the 'sequence', using loops only.
 *
 * @param sequence The main string to search for occurrences of the 'subsequence'.
 * @param subsequence The string that needs to be found within the 'sequence'.
 * @return A list containing the indices at which the 'subsequence' occurs within the 'sequence'.
 *
 * Note:
 * - The function should be case-sensitive.
 *
 * Example:
 * findSequenceOccurrences("banana", "an") // [1, 3]
 * findSequenceOccurrences("Abracadabra", "bra") // [1, 8]
 */
fun findSequenceOccurrences(sequence: String, subsequence: String): List<Int> {

    val occurrences = mutableListOf<Int>() // Empty list to store the indices of subsequence occurrences

    // Loop through the sequence to find all occurrences of the subsequence
    for (i in 0 until sequence.length) {
        if (sequence.substring(i, i + subsequence.length) == subsequence) {
            occurrences.add(i)
        }
    }

    return occurrences
}