/**
 * This exercise focuses on iterating over a list of years and appending or removing elements.
 *
 * Given two lists of historical years, find the common years present in both lists.
 *
 * @param yearsList1 A list of historical years.
 * @param yearsList2 Another list of historical years.
 * @return A list containing the common years found in both input lists.
 *
 * Example:
 * findCommonYears(listOf(1455, 1492, 1776, 1815, 1917), listOf(1492, 1776, 1917, 1945))
 * Output: [1492, 1776, 1917]
 */
fun findCommonYears(yearsList1: MutableList<Int>, yearsList2: MutableList<Int>): List<Int> {

    val iterator1 = yearsList1.iterator()
    while (iterator1.hasNext()) {
        val year = iterator1.next()
        if (year in yearsList2) {
            yearsList1.remove(year)
            yearsList2.remove(year)
        }
    }
    return yearsList1
}
/**
 * This exercise focuses on iterating over a list of years and appending or removing elements.
 *
 * Given two lists of historical years, find the common years present in both lists.
 *
 * @param yearsList1 A list of historical years.
 * @param yearsList2 Another list of historical years.
 * @return A list containing the common years found in both input lists.
 *
 * Example:
 * findCommonYears(listOf(1455, 1492, 1776, 1815, 1917), listOf(1492, 1776, 1917, 1945))
 * Output: [1492, 1776, 1917]
 */
fun findCommonYears(yearsList1: MutableList<Int>, yearsList2: MutableList<Int>): List<Int> {
/**
 * This exercise focuses on iterating over a list of years and appending or removing elements.
 *
 * Given two lists of historical years, find the common years present in both lists.
 *
 * @param yearsList1 A list of historical years.
 * @param yearsList2 Another list of historical years.
 * @return A list containing the common years found in both input lists.
 *
 * Example:
 * findCommonYears(listOf(1455, 1492, 1776, 1815, 1917), listOf(1492, 1776, 1917, 1945))
 * Output: [1492, 1776, 1917]
 */
fun findCommonYears(yearsList1: MutableList<Int>, yearsList2: MutableList<Int>): List<Int> {

    val iterator1 = yearsList1.iterator()
    while (iterator1.hasNext()) {
        val year = iterator1.next()
        if (year in yearsList2) {
            yearsList1.remove(year)
            yearsList2.remove(year)
        }
    }
    return yearsList1
}