/**
 * You are a game developer working on a new game. In this exercise, you have a list of game objects representing the
 * different elements in your game. You need to implement a function that modifies the game objects list by replacing
 * the element at a given index with a new element.
 *
 * Complete the 'modifyGameObjects' function to solve the exercise.
 *
 * @param gameObjects A list of game objects.
 * @param index An index indicating the position where the element will be replaced.
 * @param newElement The new element to replace the existing one.
 * @return The modified list of game objects.
 *
 * Example:
 * modifyGameObjects(listOf("enemy", "tree", "character", "obstacle"), 2, "power-up")
 * Output: ['enemy', 'tree', 'power-up', 'obstacle']
 */
fun modifyGameObjects(gameObjects: MutableList<String>, index: Int, newElement: String): List<String> {

    // Check if the index is valid
    if (index < 0 || index >= gameObjects.size) {
        return gameObjects
    }

    gameObjects[index] = newElement
    return gameObjects
}
/**
 * You are a game developer working on a new game. In this exercise, you have a list of game objects representing the
 * different elements in your game. You need to implement a function that modifies the game objects list by replacing
 * the element at a given index with a new element.
 *
 * Complete the 'modifyGameObjects' function to solve the exercise.
 *
 * @param gameObjects A list of game objects.
 * @param index An index indicating the position where the element will be replaced.
 * @param newElement The new element to replace the existing one.
 * @return The modified list of game objects.
 *
 * Example:
 * modifyGameObjects(listOf("enemy", "tree", "character", "obstacle"), 2, "power-up")
 * Output: ['enemy', 'tree', 'power-up', 'obstacle']
 */
fun modifyGameObjects(gameObjects: MutableList<String>, index: Int, newElement: String): List<String> {
/**
 * You are a game developer working on a new game. In this exercise, you have a list of game objects representing the
 * different elements in your game. You need to implement a function that modifies the game objects list by replacing
 * the element at a given index with a new element.
 *
 * Complete the 'modifyGameObjects' function to solve the exercise.
 *
 * @param gameObjects A list of game objects.
 * @param index An index indicating the position where the element will be replaced.
 * @param newElement The new element to replace the existing one.
 * @return The modified list of game objects.
 *
 * Example:
 * modifyGameObjects(listOf("enemy", "tree", "character", "obstacle"), 2, "power-up")
 * Output: ['enemy', 'tree', 'power-up', 'obstacle']
 */
fun modifyGameObjects(gameObjects: MutableList<String>, index: Int, newElement: String): List<String> {

    // Check if the index is valid
    if (index < 0 || index >= gameObjects.size) {
        return gameObjects
    }

    gameObjects[index] = newElement
    return gameObjects
}