/**
 * Given two strings, find the common substrings between them.
 *
 * Returns:
 * A list of common substrings found in both strings.
 *
 * Restrictions:
 * - Do not use any built-in Kotlin string methods or libraries.
 * - The solution must use a while loop to iterate over the strings.
 *
 * Example:
 * findCommonSubstrings("geology", "hello") -> ['e', 'l', 'o']
 */
fun findCommonSubstrings(str1: String, str2: String): List<String> {

    var i = 0
    val commonSubstrings = mutableListOf<String>()

    while (i < str1.length) {
        var j = 0

        while (j < str2.length) {
            var substring = ""

            while (i < str1.length && j < str2.length && str1[i] == str2[j]) {
                substring += str1[i]
                i++
                j++

                if (substring.isNotEmpty() && (i >= str1.length || j >= str2.length || str1[i] != str2[j])) {
                    commonSubstrings.add(substring)
                }
            }

            j++
        }

        i++
    }

    return commonSubstrings
}
/**
 * Given two strings, find the common substrings between them.
 *
 * Returns:
 * A list of common substrings found in both strings.
 *
 * Restrictions:
 * - Do not use any built-in Kotlin string methods or libraries.
 * - The solution must use a while loop to iterate over the strings.
 *
 * Example:
 * findCommonSubstrings("geology", "hello") -> ['e', 'l', 'o']
 */
fun findCommonSubstrings(str1: String, str2: String): List<String> {
/**
 * Given two strings, find the common substrings between them.
 *
 * Returns:
 * A list of common substrings found in both strings.
 *
 * Restrictions:
 * - Do not use any built-in Kotlin string methods or libraries.
 * - The solution must use a while loop to iterate over the strings.
 *
 * Example:
 * findCommonSubstrings("geology", "hello") -> ['e', 'l', 'o']
 */
fun findCommonSubstrings(str1: String, str2: String): List<String> {

    var i = 0
    val commonSubstrings = mutableListOf<String>()

    while (i < str1.length) {
        var j = 0

        while (j < str2.length) {
            var substring = ""

            while (i < str1.length && j < str2.length && str1[i] == str2[j]) {
                substring += str1[i]
                i++
                j++

                if (substring.isNotEmpty() && (i >= str1.length || j >= str2.length || str1[i] != str2[j])) {
                    commonSubstrings.add(substring)
                }
            }

            j++
        }

        i++
    }

    return commonSubstrings
}