/**
 * Given two arrays, find the intersection of the arrays by combining a for loop with other functions.
 *
 * @param arr1 The first array.
 * @param arr2 The second array.
 * @return The intersection of the two arrays.
 * @throws IllegalArgumentException If either of the input arrays is empty.
 *
 * Examples:
 * intersectionArrays(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) // [3, 4]
 * intersectionArrays(listOf(1, 2, 3), listOf(4, 5, 6)) // []
 */
fun intersectionArrays(arr1: List<Int>, arr2: List<Int>): List<Int> {

    if (arr1.isEmpty() || arr2.isEmpty()) {
        throw IllegalArgumentException("Input arrays should not be empty.")
    }

    val intersection = mutableListOf<Int>()
    for (num in arr1) {
        if (num in arr2 && num !in intersection) {
            intersection.add(num)
        }
    }

    return intersection
}
/**
 * Given two arrays, find the intersection of the arrays by combining a for loop with other functions.
 *
 * @param arr1 The first array.
 * @param arr2 The second array.
 * @return The intersection of the two arrays.
 * @throws IllegalArgumentException If either of the input arrays is empty.
 *
 * Examples:
 * intersectionArrays(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) // [3, 4]
 * intersectionArrays(listOf(1, 2, 3), listOf(4, 5, 6)) // []
 */
fun intersectionArrays(arr1: List<Int>, arr2: List<Int>): List<Int> {
/**
 * Given two arrays, find the intersection of the arrays by combining a for loop with other functions.
 *
 * @param arr1 The first array.
 * @param arr2 The second array.
 * @return The intersection of the two arrays.
 * @throws IllegalArgumentException If either of the input arrays is empty.
 *
 * Examples:
 * intersectionArrays(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) // [3, 4]
 * intersectionArrays(listOf(1, 2, 3), listOf(4, 5, 6)) // []
 */
fun intersectionArrays(arr1: List<Int>, arr2: List<Int>): List<Int> {

    if (arr1.isEmpty() || arr2.isEmpty()) {
        throw IllegalArgumentException("Input arrays should not be empty.")
    }

    val intersection = mutableListOf<Int>()
    for (num in arr1) {
        if (num in arr2 && num !in intersection) {
            intersection.add(num)
        }
    }

    return intersection
}