/**
 * This function takes two lists as input and returns their intersection in a new list.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return A new list containing the common elements between list1 and list2
 *
 * Example:
 * intersectionOfLists(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> [3, 4]
 */
fun intersectionOfLists(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    val mutableList1 = list1.toMutableList()
    val mutableList2 = list2.toMutableList()

    for (element1 in list1) {
        for (element2 in list2) {
            if (element1 == element2) {
                commonElements.add(element1)
                mutableList1.remove(element1)
                mutableList2.remove(element2)
                break
            }
        }
    }

    return commonElements
}
/**
 * This function takes two lists as input and returns their intersection in a new list.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return A new list containing the common elements between list1 and list2
 *
 * Example:
 * intersectionOfLists(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> [3, 4]
 */
fun intersectionOfLists(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This function takes two lists as input and returns their intersection in a new list.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return A new list containing the common elements between list1 and list2
 *
 * Example:
 * intersectionOfLists(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> [3, 4]
 */
fun intersectionOfLists(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    val mutableList1 = list1.toMutableList()
    val mutableList2 = list2.toMutableList()

    for (element1 in list1) {
        for (element2 in list2) {
            if (element1 == element2) {
                commonElements.add(element1)
                mutableList1.remove(element1)
                mutableList2.remove(element2)
                break
            }
        }
    }

    return commonElements
}