/**
 * Given two strings representing numbers, return the common digits
 * found in both strings in ascending order of their values.
 *
 * @param string1 The first number representation.
 * @param string2 The second number representation.
 * @return A list of common digits found in both strings.
 *
 * Example:
 * findCommonDigits("123456", "654321")
 * Output: [1, 2, 3, 4, 5, 6]
 */
fun findCommonDigits(string1: String, string2: String): List<Int> {

    val commonDigits = mutableListOf<Int>()

    // Iterate over each character in string1
    for (char1 in string1) {
        // Iterate over each character in string2
        for (char2 in string2) {
            // Check if the characters are digits and are equal
            if (char1.isDigit() && char2.isDigit() && char1 == char2) {
                // Convert the character to an integer and add it to commonDigits list
                val digit = Character.getNumericValue(char1)
                commonDigits.add(digit)
            }
        }
    }

    // Sort the common digits in ascending order
    commonDigits.sort()

    return commonDigits
}
/**
 * Given two strings representing numbers, return the common digits
 * found in both strings in ascending order of their values.
 *
 * @param string1 The first number representation.
 * @param string2 The second number representation.
 * @return A list of common digits found in both strings.
 *
 * Example:
 * findCommonDigits("123456", "654321")
 * Output: [1, 2, 3, 4, 5, 6]
 */
fun findCommonDigits(string1: String, string2: String): List<Int> {
/**
 * Given two strings representing numbers, return the common digits
 * found in both strings in ascending order of their values.
 *
 * @param string1 The first number representation.
 * @param string2 The second number representation.
 * @return A list of common digits found in both strings.
 *
 * Example:
 * findCommonDigits("123456", "654321")
 * Output: [1, 2, 3, 4, 5, 6]
 */
fun findCommonDigits(string1: String, string2: String): List<Int> {

    val commonDigits = mutableListOf<Int>()

    // Iterate over each character in string1
    for (char1 in string1) {
        // Iterate over each character in string2
        for (char2 in string2) {
            // Check if the characters are digits and are equal
            if (char1.isDigit() && char2.isDigit() && char1 == char2) {
                // Convert the character to an integer and add it to commonDigits list
                val digit = Character.getNumericValue(char1)
                commonDigits.add(digit)
            }
        }
    }

    // Sort the common digits in ascending order
    commonDigits.sort()

    return commonDigits
}