/**
 * Given a list of data, start and end indices, and new elements, modify the original list by replacing the elements
 * in the specified range with the new elements.
 *
 * @param data The original list of elements.
 * @param startIndex The starting index of the range to be replaced.
 * @param endIndex The ending index of the range to be replaced.
 * @param newElements The list of new elements to replace the specified range.
 * @return The modified list with the specified range replaced by the new elements.
 *
 * Example:
 * modifyElements(listOf(1, 2, 3, 4, 5, 6, 7, 8), 2, 5, listOf("A", "B")) // [1, 2, "A", "B", 6, 7, 8]
 */
fun modifyElements(data: MutableList<Any>, startIndex: Int, endIndex: Int, newElements: List<Any>): List<Any> {

    data.subList(startIndex, endIndex + 1).clear()
    data.addAll(startIndex, newElements)
    return data
}

// Create the data list
val data = mutableListOf("John", "Alice")
/**
 * Given a list of data, start and end indices, and new elements, modify the original list by replacing the elements
 * in the specified range with the new elements.
 *
 * @param data The original list of elements.
 * @param startIndex The starting index of the range to be replaced.
 * @param endIndex The ending index of the range to be replaced.
 * @param newElements The list of new elements to replace the specified range.
 * @return The modified list with the specified range replaced by the new elements.
 *
 * Example:
 * modifyElements(listOf(1, 2, 3, 4, 5, 6, 7, 8), 2, 5, listOf("A", "B")) // [1, 2, "A", "B", 6, 7, 8]
 */
fun modifyElements(data: MutableList<Any>, startIndex: Int, endIndex: Int, newElements: List<Any>): List<Any> {
/**
 * Given a list of data, start and end indices, and new elements, modify the original list by replacing the elements
 * in the specified range with the new elements.
 *
 * @param data The original list of elements.
 * @param startIndex The starting index of the range to be replaced.
 * @param endIndex The ending index of the range to be replaced.
 * @param newElements The list of new elements to replace the specified range.
 * @return The modified list with the specified range replaced by the new elements.
 *
 * Example:
 * modifyElements(listOf(1, 2, 3, 4, 5, 6, 7, 8), 2, 5, listOf("A", "B")) // [1, 2, "A", "B", 6, 7, 8]
 */
fun modifyElements(data: MutableList<Any>, startIndex: Int, endIndex: Int, newElements: List<Any>): List<Any> {

    data.subList(startIndex, endIndex + 1).clear()
    data.addAll(startIndex, newElements)
    return data
}

// Create the data list
val data = mutableListOf("John", "Alice")