/**
 * Given two arrays arr1 and arr2, your task is to find the intersection of the two arrays.
 *
 * @param arr1 List of floating-point numbers.
 * @param arr2 List of floating-point numbers.
 * @return List of floating-point numbers representing the intersection of arr1 and arr2.
 */
fun intersection(arr1: List<Double>, arr2: List<Double>): List<Double> {

    val intersectionResult = mutableListOf<Double>()

    // Sort the arrays
    val sortedArr1 = arr1.sorted()
    val sortedArr2 = arr2.sorted()

    // Set up epsilon value for floating-point comparisons
    val epsilon = 1e-9

    // Initialize indices for both arrays
    var i = 0
    var j = 0

    // Loop until one of the arrays is exhausted
    while (i < sortedArr1.size && j < sortedArr2.size) {
        // Compare the current elements using epsilon to handle floating-point errors
        if (Math.abs(sortedArr1[i] - sortedArr2[j]) < epsilon) {
            intersectionResult.add(sortedArr1[i])
            i++
            j++
        } else if (sortedArr1[i] < sortedArr2[j]) {
            i++
        } else {
            j++
        }
    }

    return intersectionResult
}
/**
 * Given two arrays arr1 and arr2, your task is to find the intersection of the two arrays.
 *
 * @param arr1 List of floating-point numbers.
 * @param arr2 List of floating-point numbers.
 * @return List of floating-point numbers representing the intersection of arr1 and arr2.
 */
fun intersection(arr1: List<Double>, arr2: List<Double>): List<Double> {
/**
 * Given two arrays arr1 and arr2, your task is to find the intersection of the two arrays.
 *
 * @param arr1 List of floating-point numbers.
 * @param arr2 List of floating-point numbers.
 * @return List of floating-point numbers representing the intersection of arr1 and arr2.
 */
fun intersection(arr1: List<Double>, arr2: List<Double>): List<Double> {

    val intersectionResult = mutableListOf<Double>()

    // Sort the arrays
    val sortedArr1 = arr1.sorted()
    val sortedArr2 = arr2.sorted()

    // Set up epsilon value for floating-point comparisons
    val epsilon = 1e-9

    // Initialize indices for both arrays
    var i = 0
    var j = 0

    // Loop until one of the arrays is exhausted
    while (i < sortedArr1.size && j < sortedArr2.size) {
        // Compare the current elements using epsilon to handle floating-point errors
        if (Math.abs(sortedArr1[i] - sortedArr2[j]) < epsilon) {
            intersectionResult.add(sortedArr1[i])
            i++
            j++
        } else if (sortedArr1[i] < sortedArr2[j]) {
            i++
        } else {
            j++
        }
    }

    return intersectionResult
}