/**
 * Given two sets, this function finds and returns the common elements between them.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return A set containing the common elements between set1 and set2.
 */
fun findCommonElements(set1: Set<Any>, set2: MutableSet<Any>): Set<Any> {

    val commonElements = mutableSetOf<Any>()

    // Loop through set1 using a for loop
    for (elem in set1) {
        // Check if the current element is present in set2 using a while loop
        while (elem in set2) {
            commonElements.add(elem)
            // Remove the common element from set2 to avoid repetitions
            set2.remove(elem) // Potentially modifying set2 while looping
        }
    }

    return commonElements
}
/**
 * Given two sets, this function finds and returns the common elements between them.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return A set containing the common elements between set1 and set2.
 */
fun findCommonElements(set1: Set<Any>, set2: MutableSet<Any>): Set<Any> {
/**
 * Given two sets, this function finds and returns the common elements between them.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return A set containing the common elements between set1 and set2.
 */
fun findCommonElements(set1: Set<Any>, set2: MutableSet<Any>): Set<Any> {

    val commonElements = mutableSetOf<Any>()

    // Loop through set1 using a for loop
    for (elem in set1) {
        // Check if the current element is present in set2 using a while loop
        while (elem in set2) {
            commonElements.add(elem)
            // Remove the common element from set2 to avoid repetitions
            set2.remove(elem) // Potentially modifying set2 while looping
        }
    }

    return commonElements
}