/**
 * This function takes two sets as input and returns their intersection.
 *
 * @param set1 The first set
 * @param set2 The second set
 * @return The intersection of set1 and set2
 */
fun intersectionOfSets(set1: Set<Int>, set2: Set<Int>): Set<Int> {

    // Convert sets to lists
    val list1 = set1.toList().sorted()
    val list2 = set2.toList().sorted()

    // Initialize variables
    val intersectSet = mutableSetOf<Int>()
    var ptr1 = 0
    var ptr2 = 0

    // Loop through the lists and find common elements
    while (ptr1 < list1.size && ptr2 < list2.size) {
        when {
            list1[ptr1] < list2[ptr2] -> ptr1++
            list1[ptr1] > list2[ptr2] -> ptr2++
            else -> {
                intersectSet.add(list1[ptr1])
                ptr1++
                ptr2++
            }
        }
    }

    return intersectSet
}
/**
 * This function takes two sets as input and returns their intersection.
 *
 * @param set1 The first set
 * @param set2 The second set
 * @return The intersection of set1 and set2
 */
fun intersectionOfSets(set1: Set<Int>, set2: Set<Int>): Set<Int> {
/**
 * This function takes two sets as input and returns their intersection.
 *
 * @param set1 The first set
 * @param set2 The second set
 * @return The intersection of set1 and set2
 */
fun intersectionOfSets(set1: Set<Int>, set2: Set<Int>): Set<Int> {

    // Convert sets to lists
    val list1 = set1.toList().sorted()
    val list2 = set2.toList().sorted()

    // Initialize variables
    val intersectSet = mutableSetOf<Int>()
    var ptr1 = 0
    var ptr2 = 0

    // Loop through the lists and find common elements
    while (ptr1 < list1.size && ptr2 < list2.size) {
        when {
            list1[ptr1] < list2[ptr2] -> ptr1++
            list1[ptr1] > list2[ptr2] -> ptr2++
            else -> {
                intersectSet.add(list1[ptr1])
                ptr1++
                ptr2++
            }
        }
    }

    return intersectSet
}