/**
 * Given two lists, find and return the common elements between them.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements between list1 and list2.
 * @throws IllegalArgumentException If any of the input lists is empty.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> [3, 4]
 * findCommonElements(listOf(1, 2, 3), listOf(4, 5, 6)) -> []
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    if (list1.isEmpty() || list2.isEmpty()) {
        throw IllegalArgumentException("Input lists cannot be empty!")
    }

    val commonElements = mutableListOf<Int>()

    for (element in list1) {
        if (element in list2) {
            commonElements.add(element)
        }
    }

    return commonElements
}
/**
 * Given two lists, find and return the common elements between them.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements between list1 and list2.
 * @throws IllegalArgumentException If any of the input lists is empty.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> [3, 4]
 * findCommonElements(listOf(1, 2, 3), listOf(4, 5, 6)) -> []
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find and return the common elements between them.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements between list1 and list2.
 * @throws IllegalArgumentException If any of the input lists is empty.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4), listOf(3, 4, 5, 6)) -> [3, 4]
 * findCommonElements(listOf(1, 2, 3), listOf(4, 5, 6)) -> []
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    if (list1.isEmpty() || list2.isEmpty()) {
        throw IllegalArgumentException("Input lists cannot be empty!")
    }

    val commonElements = mutableListOf<Int>()

    for (element in list1) {
        if (element in list2) {
            commonElements.add(element)
        }
    }

    return commonElements
}