/**
 * Given an array of integers, modify the elements within a specified range with new elements.
 *
 * @param array The list of integers.
 * @param start The starting index of the range to be modified.
 * @param end The ending index of the range to be modified.
 * @param newElements The list of new elements to replace the range with.
 * @return The modified list of integers.
 */
fun modifyElements(array: MutableList<Int>, start: Int, end: Int, newElements: List<Int>): List<Int> {

    // Check if the range is valid
    if (start >= end || end > array.size) {
        return listOf(-1) // Return a list with -1 to indicate an error
    }

    // Check if the new elements have the same length as the range
    if (newElements.size != end - start) {
        return listOf(-2) // Return a list with -2 to indicate an error
    }

    // Modify the elements within the specified range
    array.subList(start, end).clear()
    array.addAll(start, newElements)

    return array
}
/**
 * Given an array of integers, modify the elements within a specified range with new elements.
 *
 * @param array The list of integers.
 * @param start The starting index of the range to be modified.
 * @param end The ending index of the range to be modified.
 * @param newElements The list of new elements to replace the range with.
 * @return The modified list of integers.
 */
fun modifyElements(array: MutableList<Int>, start: Int, end: Int, newElements: List<Int>): List<Int> {
/**
 * Given an array of integers, modify the elements within a specified range with new elements.
 *
 * @param array The list of integers.
 * @param start The starting index of the range to be modified.
 * @param end The ending index of the range to be modified.
 * @param newElements The list of new elements to replace the range with.
 * @return The modified list of integers.
 */
fun modifyElements(array: MutableList<Int>, start: Int, end: Int, newElements: List<Int>): List<Int> {

    // Check if the range is valid
    if (start >= end || end > array.size) {
        return listOf(-1) // Return a list with -1 to indicate an error
    }

    // Check if the new elements have the same length as the range
    if (newElements.size != end - start) {
        return listOf(-2) // Return a list with -2 to indicate an error
    }

    // Modify the elements within the specified range
    array.subList(start, end).clear()
    array.addAll(start, newElements)

    return array
}