/**
 * A carpenter needs to replace selected boards in a wooden structure.
 * The structure is represented as a list of board lengths.
 *
 * Complete the code below to replace the boards in the structure by
 * slicing and replacing elements.
 *
 * @param boards A list of integers representing the lengths of the boards
 * @param replacements A map indicating the positions and lengths
 *                     of the new boards to be inserted
 * @return A list representing the modified wooden structure
 *
 * Example:
 * replaceBoards(listOf(2, 4, 6, 8, 10), mapOf(1 to 5, 3 to 7)) -> [2, 5, 6, 7, 10]
 * Explanation: The board at position 1 in the original structure (4) is
 * replaced by a new board of length 5. Similarly, the board
 * at position 3 (8) is replaced by a new board of length 7.
 */
fun replaceBoards(boards: List<Int>, replacements: Map<Int, Int>): List<Int> {

    val modifiedBoards = boards.toMutableList()

    for ((position, length) in replacements) {
        modifiedBoards[position] = length
    }

    return modifiedBoards
}
/**
 * A carpenter needs to replace selected boards in a wooden structure.
 * The structure is represented as a list of board lengths.
 *
 * Complete the code below to replace the boards in the structure by
 * slicing and replacing elements.
 *
 * @param boards A list of integers representing the lengths of the boards
 * @param replacements A map indicating the positions and lengths
 *                     of the new boards to be inserted
 * @return A list representing the modified wooden structure
 *
 * Example:
 * replaceBoards(listOf(2, 4, 6, 8, 10), mapOf(1 to 5, 3 to 7)) -> [2, 5, 6, 7, 10]
 * Explanation: The board at position 1 in the original structure (4) is
 * replaced by a new board of length 5. Similarly, the board
 * at position 3 (8) is replaced by a new board of length 7.
 */
fun replaceBoards(boards: List<Int>, replacements: Map<Int, Int>): List<Int> {
/**
 * A carpenter needs to replace selected boards in a wooden structure.
 * The structure is represented as a list of board lengths.
 *
 * Complete the code below to replace the boards in the structure by
 * slicing and replacing elements.
 *
 * @param boards A list of integers representing the lengths of the boards
 * @param replacements A map indicating the positions and lengths
 *                     of the new boards to be inserted
 * @return A list representing the modified wooden structure
 *
 * Example:
 * replaceBoards(listOf(2, 4, 6, 8, 10), mapOf(1 to 5, 3 to 7)) -> [2, 5, 6, 7, 10]
 * Explanation: The board at position 1 in the original structure (4) is
 * replaced by a new board of length 5. Similarly, the board
 * at position 3 (8) is replaced by a new board of length 7.
 */
fun replaceBoards(boards: List<Int>, replacements: Map<Int, Int>): List<Int> {

    val modifiedBoards = boards.toMutableList()

    for ((position, length) in replacements) {
        modifiedBoards[position] = length
    }

    return modifiedBoards
}