/**
 * Given two lists, return a new list containing the elements that are common to both lists.
 * The lists can contain any data type.
 *
 * @param list1 The first list
 * @param list2 The second list
 * @return A new list containing the common elements from list1 and list2
 *
 * Example:
 * intersectAndCopyList(listOf(1, 2, "a", "b"), listOf("a", "b", 3, 4)) => listOf("a", "b")
 */
fun intersectAndCopyList(list1: List<Any>, list2: List<Any>): List<Any> {

    val intersectedList = mutableListOf<Any>()

    // Find the intersection of the lists
    for (element in list1) {
        if (element in list2) {
            intersectedList.add(element)
        }
    }

    // Create a deep copy of the intersected list
    val copiedList = intersectedList.toMutableList()

    return copiedList
}
/**
 * Given two lists, return a new list containing the elements that are common to both lists.
 * The lists can contain any data type.
 *
 * @param list1 The first list
 * @param list2 The second list
 * @return A new list containing the common elements from list1 and list2
 *
 * Example:
 * intersectAndCopyList(listOf(1, 2, "a", "b"), listOf("a", "b", 3, 4)) => listOf("a", "b")
 */
fun intersectAndCopyList(list1: List<Any>, list2: List<Any>): List<Any> {
/**
 * Given two lists, return a new list containing the elements that are common to both lists.
 * The lists can contain any data type.
 *
 * @param list1 The first list
 * @param list2 The second list
 * @return A new list containing the common elements from list1 and list2
 *
 * Example:
 * intersectAndCopyList(listOf(1, 2, "a", "b"), listOf("a", "b", 3, 4)) => listOf("a", "b")
 */
fun intersectAndCopyList(list1: List<Any>, list2: List<Any>): List<Any> {

    val intersectedList = mutableListOf<Any>()

    // Find the intersection of the lists
    for (element in list1) {
        if (element in list2) {
            intersectedList.add(element)
        }
    }

    // Create a deep copy of the intersected list
    val copiedList = intersectedList.toMutableList()

    return copiedList
}