/**
 * Given two arrays of integers, replace the intersecting elements with the sum of the two elements.
 *
 * @param array1 the first array of integers
 * @param array2 the second array of integers
 * @return a new array with the intersecting elements replaced
 *
 * Example:
 * replaceElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [1, 2, 3, 9, 13]
 */
fun replaceElements(array1: List<Int>, array2: List<Int>): List<Int> {

    val newArray = array1.toMutableList()

    for (i in array1.indices) {
        if (array1[i] in array2) {
            newArray[i] += array2[array2.indexOf(array1[i])]
        }
    }

    return newArray
}
/**
 * Given two arrays of integers, replace the intersecting elements with the sum of the two elements.
 *
 * @param array1 the first array of integers
 * @param array2 the second array of integers
 * @return a new array with the intersecting elements replaced
 *
 * Example:
 * replaceElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [1, 2, 3, 9, 13]
 */
fun replaceElements(array1: List<Int>, array2: List<Int>): List<Int> {
/**
 * Given two arrays of integers, replace the intersecting elements with the sum of the two elements.
 *
 * @param array1 the first array of integers
 * @param array2 the second array of integers
 * @return a new array with the intersecting elements replaced
 *
 * Example:
 * replaceElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [1, 2, 3, 9, 13]
 */
fun replaceElements(array1: List<Int>, array2: List<Int>): List<Int> {

    val newArray = array1.toMutableList()

    for (i in array1.indices) {
        if (array1[i] in array2) {
            newArray[i] += array2[array2.indexOf(array1[i])]
        }
    }

    return newArray
}