/**
 * Given a list of elements and a replacement value, replace the n-th occurrence of a given element in the list with the replacement value.
 *
 * @param n The number of occurrence to replace.
 * @param elements The list of elements.
 * @param idx The index of the element to replace.
 * @param replacement The value to replace the element with.
 * @return The updated list with the replacement made.
 */
fun replaceElement(n: Int, elements: MutableList<Int>, idx: Int, replacement: Int): List<Int> {

    var count = 0
    var i = 0
    while (i < elements.size) {
        if (elements[i] == idx) {
            count++
            if (count == n) {
                elements[i] = replacement
                break
            }
        }
        i++
    }
    return elements
}
/**
 * Given a list of elements and a replacement value, replace the n-th occurrence of a given element in the list with the replacement value.
 *
 * @param n The number of occurrence to replace.
 * @param elements The list of elements.
 * @param idx The index of the element to replace.
 * @param replacement The value to replace the element with.
 * @return The updated list with the replacement made.
 */
fun replaceElement(n: Int, elements: MutableList<Int>, idx: Int, replacement: Int): List<Int> {
/**
 * Given a list of elements and a replacement value, replace the n-th occurrence of a given element in the list with the replacement value.
 *
 * @param n The number of occurrence to replace.
 * @param elements The list of elements.
 * @param idx The index of the element to replace.
 * @param replacement The value to replace the element with.
 * @return The updated list with the replacement made.
 */
fun replaceElement(n: Int, elements: MutableList<Int>, idx: Int, replacement: Int): List<Int> {

    var count = 0
    var i = 0
    while (i < elements.size) {
        if (elements[i] == idx) {
            count++
            if (count == n) {
                elements[i] = replacement
                break
            }
        }
        i++
    }
    return elements
}