/**
 * Given a list of actor/actress names, modify the list by replacing all occurrences
 * of the oldName with the newName.
 *
 * @param actorsList A list of actor/actress names.
 * @param oldName The name to be replaced.
 * @param newName The name to replace the oldName.
 * @return The modified list with replaced names.
 */
fun modifyActorList(actorsList: MutableList<String>, oldName: String, newName: String): List<String> {

    // Check if oldName exists in the list, if not, return the original list
    if (oldName !in actorsList) {
        return actorsList
    }

    // Find indexes of all occurrences of oldName in the list
    val indexes = actorsList.mapIndexedNotNull { index, name -> if (name == oldName) index else null }

    // Iterate through the indexes list in reverse order
    for (i in indexes.reversed()) {
        // Delete the oldName at the current index
        actorsList.removeAt(i)
        // Insert the newName at the same index
        actorsList.add(i, newName)
    }

    return actorsList
}
/**
 * Given a list of actor/actress names, modify the list by replacing all occurrences
 * of the oldName with the newName.
 *
 * @param actorsList A list of actor/actress names.
 * @param oldName The name to be replaced.
 * @param newName The name to replace the oldName.
 * @return The modified list with replaced names.
 */
fun modifyActorList(actorsList: MutableList<String>, oldName: String, newName: String): List<String> {
/**
 * Given a list of actor/actress names, modify the list by replacing all occurrences
 * of the oldName with the newName.
 *
 * @param actorsList A list of actor/actress names.
 * @param oldName The name to be replaced.
 * @param newName The name to replace the oldName.
 * @return The modified list with replaced names.
 */
fun modifyActorList(actorsList: MutableList<String>, oldName: String, newName: String): List<String> {

    // Check if oldName exists in the list, if not, return the original list
    if (oldName !in actorsList) {
        return actorsList
    }

    // Find indexes of all occurrences of oldName in the list
    val indexes = actorsList.mapIndexedNotNull { index, name -> if (name == oldName) index else null }

    // Iterate through the indexes list in reverse order
    for (i in indexes.reversed()) {
        // Delete the oldName at the current index
        actorsList.removeAt(i)
        // Insert the newName at the same index
        actorsList.add(i, newName)
    }

    return actorsList
}