/**
 * Given two lists, find the common elements between them using sets and the intersect operator.
 *
 * @param list1 The first list
 * @param list2 The second list
 * @return A new list containing the common elements between list1 and list2
 *
 * Example:
 * getCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun getCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    // Convert the lists into sets to efficiently perform intersection
    val set1 = list1.toSet()
    val set2 = list2.toSet()

    // Use the intersect operator to get all elements of set1 that are also in set2
    val commonElements = set1.intersect(set2).toList()

    return commonElements
}
/**
 * Given two lists, find the common elements between them using sets and the intersect operator.
 *
 * @param list1 The first list
 * @param list2 The second list
 * @return A new list containing the common elements between list1 and list2
 *
 * Example:
 * getCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun getCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find the common elements between them using sets and the intersect operator.
 *
 * @param list1 The first list
 * @param list2 The second list
 * @return A new list containing the common elements between list1 and list2
 *
 * Example:
 * getCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun getCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    // Convert the lists into sets to efficiently perform intersection
    val set1 = list1.toSet()
    val set2 = list2.toSet()

    // Use the intersect operator to get all elements of set1 that are also in set2
    val commonElements = set1.intersect(set2).toList()

    return commonElements
}