/**
 * This exercise requires you to slice a given list of elements and replace all occurrences of 'old'
 * with 'new', while also making sure that the replacement only happens when the element in the list
 * is not equal to 'new'.
 *
 * @param elements A list of elements.
 * @param old The element to be replaced.
 * @param new The new element to replace 'old' with.
 * @return A modified list with the replacements made.
 */
fun sliceAndReplaceNotEqual(elements: MutableList<Int>, old: Int, new: Int): List<Int> {

    // Check if 'old' is not equal to 'new', otherwise return the original list
    if (old == new) {
        return elements
    }

    // Iterate over the list and replace 'old' with 'new' if the element is not equal to 'new'
    for (i in elements.indices) {
        if (elements[i] != new) {
            elements[i] = new
        }
    }

    // Return the modified list with replacements made
    return elements
}

// Example usage
val originalList = mutableListOf(1, 2, 3, 4, 5, 4, 6, 4)
val result = sliceAndReplaceNotEqual(originalList.subList(1, 6), 4, 7)
/**
 * This exercise requires you to slice a given list of elements and replace all occurrences of 'old'
 * with 'new', while also making sure that the replacement only happens when the element in the list
 * is not equal to 'new'.
 *
 * @param elements A list of elements.
 * @param old The element to be replaced.
 * @param new The new element to replace 'old' with.
 * @return A modified list with the replacements made.
 */
fun sliceAndReplaceNotEqual(elements: MutableList<Int>, old: Int, new: Int): List<Int> {
/**
 * This exercise requires you to slice a given list of elements and replace all occurrences of 'old'
 * with 'new', while also making sure that the replacement only happens when the element in the list
 * is not equal to 'new'.
 *
 * @param elements A list of elements.
 * @param old The element to be replaced.
 * @param new The new element to replace 'old' with.
 * @return A modified list with the replacements made.
 */
fun sliceAndReplaceNotEqual(elements: MutableList<Int>, old: Int, new: Int): List<Int> {

    // Check if 'old' is not equal to 'new', otherwise return the original list
    if (old == new) {
        return elements
    }

    // Iterate over the list and replace 'old' with 'new' if the element is not equal to 'new'
    for (i in elements.indices) {
        if (elements[i] != new) {
            elements[i] = new
        }
    }

    // Return the modified list with replacements made
    return elements
}

// Example usage
val originalList = mutableListOf(1, 2, 3, 4, 5, 4, 6, 4)
val result = sliceAndReplaceNotEqual(originalList.subList(1, 6), 4, 7)