/**
 * You are a teacher and want to modify a string by replacing certain characters at specific indices.
 * Write a function that takes a string and a list of indices as input and returns the modified string.
 *
 * Hint: Use a while loop to iterate through the list of indices.
 *
 * @param string Original string
 * @param indices List of indices where characters need to be replaced
 * @return Modified string
 *
 * Example:
 * modifyString("Hello, World!", listOf(1, 4, 8)) -> "Hxllo, Wxrld!"
 */
fun modifyString(string: String, indices: List<Int>): String {

    var i = 0
    var modifiedString = string

    while (i < indices.size) {
        val index = indices[i]
        if (index in 0 until modifiedString.length) {
            modifiedString = modifiedString.substring(0, index) + 'x' + modifiedString.substring(index + 1)
            i++
        } else {
            indices.toMutableList().removeAt(i)
        }
    }

    return modifiedString
}
/**
 * You are a teacher and want to modify a string by replacing certain characters at specific indices.
 * Write a function that takes a string and a list of indices as input and returns the modified string.
 *
 * Hint: Use a while loop to iterate through the list of indices.
 *
 * @param string Original string
 * @param indices List of indices where characters need to be replaced
 * @return Modified string
 *
 * Example:
 * modifyString("Hello, World!", listOf(1, 4, 8)) -> "Hxllo, Wxrld!"
 */
fun modifyString(string: String, indices: List<Int>): String {
/**
 * You are a teacher and want to modify a string by replacing certain characters at specific indices.
 * Write a function that takes a string and a list of indices as input and returns the modified string.
 *
 * Hint: Use a while loop to iterate through the list of indices.
 *
 * @param string Original string
 * @param indices List of indices where characters need to be replaced
 * @return Modified string
 *
 * Example:
 * modifyString("Hello, World!", listOf(1, 4, 8)) -> "Hxllo, Wxrld!"
 */
fun modifyString(string: String, indices: List<Int>): String {

    var i = 0
    var modifiedString = string

    while (i < indices.size) {
        val index = indices[i]
        if (index in 0 until modifiedString.length) {
            modifiedString = modifiedString.substring(0, index) + 'x' + modifiedString.substring(index + 1)
            i++
        } else {
            indices.toMutableList().removeAt(i)
        }
    }

    return modifiedString
}