/**
 * Given a sentence and a substring, find the substring in the sentence and break out of the loop after 'maxIterations' iterations.
 * Return the portion of the sentence that comes after the last occurrence of the substring.
 *
 * @param sentence The sentence to search in.
 * @param substring The substring to find.
 * @param maxIterations The maximum number of iterations to perform before breaking out of the loop.
 * @return The portion of the sentence that comes after the last occurrence of the substring.
 */
fun findSubstring(sentence: String, substring: String, maxIterations: Int): String {

    var foundIndex = -1
    var count = 0

    while (count < maxIterations) {
        val index = sentence.indexOf(substring, foundIndex + 1)

        if (index == -1) {
            break
        }

        foundIndex = index
        count++
    }

    return if (foundIndex != -1) {
        sentence.substring(foundIndex + substring.length)
    } else {
        ""
    }
}
/**
 * Given a sentence and a substring, find the substring in the sentence and break out of the loop after 'maxIterations' iterations.
 * Return the portion of the sentence that comes after the last occurrence of the substring.
 *
 * @param sentence The sentence to search in.
 * @param substring The substring to find.
 * @param maxIterations The maximum number of iterations to perform before breaking out of the loop.
 * @return The portion of the sentence that comes after the last occurrence of the substring.
 */
fun findSubstring(sentence: String, substring: String, maxIterations: Int): String {
/**
 * Given a sentence and a substring, find the substring in the sentence and break out of the loop after 'maxIterations' iterations.
 * Return the portion of the sentence that comes after the last occurrence of the substring.
 *
 * @param sentence The sentence to search in.
 * @param substring The substring to find.
 * @param maxIterations The maximum number of iterations to perform before breaking out of the loop.
 * @return The portion of the sentence that comes after the last occurrence of the substring.
 */
fun findSubstring(sentence: String, substring: String, maxIterations: Int): String {

    var foundIndex = -1
    var count = 0

    while (count < maxIterations) {
        val index = sentence.indexOf(substring, foundIndex + 1)

        if (index == -1) {
            break
        }

        foundIndex = index
        count++
    }

    return if (foundIndex != -1) {
        sentence.substring(foundIndex + substring.length)
    } else {
        ""
    }
}