/**
 * Given two arrays, arr1 and arr2, find the intersection of the two arrays using slicing and a basic for loop.
 *
 * @param arr1 The first array.
 * @param arr2 The second array.
 * @return The intersection of the two arrays.
 */
fun intersectionSlicingLoop(arr1: List<Int>, arr2: List<Int>): List<Int> {

    val result = mutableListOf<Int>()

    // Sorting the arrays to perform slicing (optional if already sorted)
    val sortedArr1 = arr1.sorted()
    val sortedArr2 = arr2.sorted()

    // Storing unique elements from arr1
    val uniqueArr1 = sortedArr1.toSet().toList()

    // Basic for loop to iterate through uniqueArr1
    for (i in uniqueArr1.indices) {
        // Slicing the array from the current element to the end
        val slicedArr2 = sortedArr2.subList(sortedArr2.indexOf(uniqueArr1[i]), sortedArr2.size)

        // Checking if the current element exists in slicedArr2
        if (uniqueArr1[i] in slicedArr2) {
            result.add(uniqueArr1[i])
        }
    }

    return result
}
/**
 * Given two arrays, arr1 and arr2, find the intersection of the two arrays using slicing and a basic for loop.
 *
 * @param arr1 The first array.
 * @param arr2 The second array.
 * @return The intersection of the two arrays.
 */
fun intersectionSlicingLoop(arr1: List<Int>, arr2: List<Int>): List<Int> {
/**
 * Given two arrays, arr1 and arr2, find the intersection of the two arrays using slicing and a basic for loop.
 *
 * @param arr1 The first array.
 * @param arr2 The second array.
 * @return The intersection of the two arrays.
 */
fun intersectionSlicingLoop(arr1: List<Int>, arr2: List<Int>): List<Int> {

    val result = mutableListOf<Int>()

    // Sorting the arrays to perform slicing (optional if already sorted)
    val sortedArr1 = arr1.sorted()
    val sortedArr2 = arr2.sorted()

    // Storing unique elements from arr1
    val uniqueArr1 = sortedArr1.toSet().toList()

    // Basic for loop to iterate through uniqueArr1
    for (i in uniqueArr1.indices) {
        // Slicing the array from the current element to the end
        val slicedArr2 = sortedArr2.subList(sortedArr2.indexOf(uniqueArr1[i]), sortedArr2.size)

        // Checking if the current element exists in slicedArr2
        if (uniqueArr1[i] in slicedArr2) {
            result.add(uniqueArr1[i])
        }
    }

    return result
}