/**
 * The goal of this exercise is to find the index of the last occurrence of a substring within a string.
 *
 * Given a string and a substring, write a function that returns the index of the last occurrence of the substring within the string.
 * If the substring is not found, the function should return -1.
 *
 * Example:
 * string = "Environmental scientists study the environment and how living organisms affect it."
 * substring = "environment"
 *
 * The expected output is 41.
 */
fun intersectionExercise(string: String, substring: String): Int {

    // Find the last index of the substring within the string using string slicing and the indexOf method
    try {
        val index = string.indexOf(substring.reversed())
        return string.length - index - substring.length
    } catch (e: NoSuchElementException) {
        return -1
    }
}
/**
 * The goal of this exercise is to find the index of the last occurrence of a substring within a string.
 *
 * Given a string and a substring, write a function that returns the index of the last occurrence of the substring within the string.
 * If the substring is not found, the function should return -1.
 *
 * Example:
 * string = "Environmental scientists study the environment and how living organisms affect it."
 * substring = "environment"
 *
 * The expected output is 41.
 */
fun intersectionExercise(string: String, substring: String): Int {
/**
 * The goal of this exercise is to find the index of the last occurrence of a substring within a string.
 *
 * Given a string and a substring, write a function that returns the index of the last occurrence of the substring within the string.
 * If the substring is not found, the function should return -1.
 *
 * Example:
 * string = "Environmental scientists study the environment and how living organisms affect it."
 * substring = "environment"
 *
 * The expected output is 41.
 */
fun intersectionExercise(string: String, substring: String): Int {

    // Find the last index of the substring within the string using string slicing and the indexOf method
    try {
        val index = string.indexOf(substring.reversed())
        return string.length - index - substring.length
    } catch (e: NoSuchElementException) {
        return -1
    }
}