/**
 * Given two lists, find the common elements between them using nested loops and sets.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements between list1 and list2.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate through all possible pairs of elements from list1 and list2
    for (elem1 in list1) {
        for (elem2 in list2) {
            // Check if the elements are equal and not already in the commonElements list
            if (elem1 == elem2 && elem1 !in commonElements) {
                commonElements.add(elem1)
            }
        }
    }

    return commonElements
}
/**
 * Given two lists, find the common elements between them using nested loops and sets.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements between list1 and list2.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find the common elements between them using nested loops and sets.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements between list1 and list2.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate through all possible pairs of elements from list1 and list2
    for (elem1 in list1) {
        for (elem2 in list2) {
            // Check if the elements are equal and not already in the commonElements list
            if (elem1 == elem2 && elem1 !in commonElements) {
                commonElements.add(elem1)
            }
        }
    }

    return commonElements
}