/**
 * Given a list of negative integers [nums], replace the element at the given [indexToReplace] with the [newElement].
 * If the index is out of range, return an empty list.
 *
 * @param nums A list of negative integers.
 * @param indexToReplace An integer representing the index to be replaced.
 * @param newElement An integer representing the new element to replace at the given index.
 * @return A list of integers, where the element at the given index is replaced with the new element.
 *
 * Example:
 * Input: sliceAndReplaceElectrician(listOf(-5, -10, -15, -20), 2, -25)
 * Output: [-5, -10, -25, -20]
 */
fun sliceAndReplaceElectrician(nums: List<Int>, indexToReplace: Int, newElement: Int): List<Int> {

    // Validate if index is out of range
    if (indexToReplace < 0 || indexToReplace >= nums.size) {
        return emptyList()
    }

    // Perform slicing and replacing
    val updatedList = nums.toMutableList()
    updatedList[indexToReplace] = newElement

    return updatedList
}
/**
 * Given a list of negative integers [nums], replace the element at the given [indexToReplace] with the [newElement].
 * If the index is out of range, return an empty list.
 *
 * @param nums A list of negative integers.
 * @param indexToReplace An integer representing the index to be replaced.
 * @param newElement An integer representing the new element to replace at the given index.
 * @return A list of integers, where the element at the given index is replaced with the new element.
 *
 * Example:
 * Input: sliceAndReplaceElectrician(listOf(-5, -10, -15, -20), 2, -25)
 * Output: [-5, -10, -25, -20]
 */
fun sliceAndReplaceElectrician(nums: List<Int>, indexToReplace: Int, newElement: Int): List<Int> {
/**
 * Given a list of negative integers [nums], replace the element at the given [indexToReplace] with the [newElement].
 * If the index is out of range, return an empty list.
 *
 * @param nums A list of negative integers.
 * @param indexToReplace An integer representing the index to be replaced.
 * @param newElement An integer representing the new element to replace at the given index.
 * @return A list of integers, where the element at the given index is replaced with the new element.
 *
 * Example:
 * Input: sliceAndReplaceElectrician(listOf(-5, -10, -15, -20), 2, -25)
 * Output: [-5, -10, -25, -20]
 */
fun sliceAndReplaceElectrician(nums: List<Int>, indexToReplace: Int, newElement: Int): List<Int> {

    // Validate if index is out of range
    if (indexToReplace < 0 || indexToReplace >= nums.size) {
        return emptyList()
    }

    // Perform slicing and replacing
    val updatedList = nums.toMutableList()
    updatedList[indexToReplace] = newElement

    return updatedList
}