/**
 * Given two lists, find the common elements by taking their intersection using modulus and slicing.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5, 6, 7, 8), listOf(2, 4, 6, 8)) // [2, 4, 6, 8]
 * findCommonElements(listOf(10, 20, 30, 40, 50), listOf(5, 10, 15, 20, 25, 30, 35, 40)) // [10, 20, 30, 40]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Find the common elements using the modulo operator and slicing
    for (num in list1) {
        if (list2.subList(0, list2.size % list1.size).contains(num)) {
            commonElements.add(num)
        }
    }

    return commonElements
}
/**
 * Given two lists, find the common elements by taking their intersection using modulus and slicing.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5, 6, 7, 8), listOf(2, 4, 6, 8)) // [2, 4, 6, 8]
 * findCommonElements(listOf(10, 20, 30, 40, 50), listOf(5, 10, 15, 20, 25, 30, 35, 40)) // [10, 20, 30, 40]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find the common elements by taking their intersection using modulus and slicing.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5, 6, 7, 8), listOf(2, 4, 6, 8)) // [2, 4, 6, 8]
 * findCommonElements(listOf(10, 20, 30, 40, 50), listOf(5, 10, 15, 20, 25, 30, 35, 40)) // [10, 20, 30, 40]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Find the common elements using the modulo operator and slicing
    for (num in list1) {
        if (list2.subList(0, list2.size % list1.size).contains(num)) {
            commonElements.add(num)
        }
    }

    return commonElements
}