/**
 * Given a string and a list of characters, appends each character to the end of the string and finds the positions of
 * all occurrences of that character in the updated string using loops.
 *
 * @param string Input string.
 * @param chars List of characters to append and find positions for.
 * @return List of pairs, each containing the appended character and a list of positions where it occurs in the string.
 */
fun appendAndFindChars(string: String, chars: List<Char>): List<Pair<Char, List<Int>>> {

    var appendedString = string
    val positionsList = mutableListOf<Pair<Char, List<Int>>>()

    for (char in chars) {
        appendedString += char  // Append character to the end of the string

        val positions = mutableListOf<Int>()
        for (i in appendedString.indices) {  // Loop through each index of the string
            if (appendedString[i] == char) {  // If character at index i matches the current character
                positions.add(i)  // Append the index to the positions list
            }
        }

        positionsList.add(Pair(char, positions))  // Append pair of character and positions to the positions list
    }

    return positionsList
}
/**
 * Given a string and a list of characters, appends each character to the end of the string and finds the positions of
 * all occurrences of that character in the updated string using loops.
 *
 * @param string Input string.
 * @param chars List of characters to append and find positions for.
 * @return List of pairs, each containing the appended character and a list of positions where it occurs in the string.
 */
fun appendAndFindChars(string: String, chars: List<Char>): List<Pair<Char, List<Int>>> {
/**
 * Given a string and a list of characters, appends each character to the end of the string and finds the positions of
 * all occurrences of that character in the updated string using loops.
 *
 * @param string Input string.
 * @param chars List of characters to append and find positions for.
 * @return List of pairs, each containing the appended character and a list of positions where it occurs in the string.
 */
fun appendAndFindChars(string: String, chars: List<Char>): List<Pair<Char, List<Int>>> {

    var appendedString = string
    val positionsList = mutableListOf<Pair<Char, List<Int>>>()

    for (char in chars) {
        appendedString += char  // Append character to the end of the string

        val positions = mutableListOf<Int>()
        for (i in appendedString.indices) {  // Loop through each index of the string
            if (appendedString[i] == char) {  // If character at index i matches the current character
                positions.add(i)  // Append the index to the positions list
            }
        }

        positionsList.add(Pair(char, positions))  // Append pair of character and positions to the positions list
    }

    return positionsList
}