/**
 * Given two lists, find and return a new list containing the elements that are present in both lists.
 *
 * @param list1 First list
 * @param list2 Second list
 * @return List of common elements
 *
 * Example:
 * intersectLists(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun intersectLists(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    for (elem in list1) {
        if (elem in list2) {
            commonElements.add(elem)
        }
    }
    return commonElements
}
/**
 * Given two lists, find and return a new list containing the elements that are present in both lists.
 *
 * @param list1 First list
 * @param list2 Second list
 * @return List of common elements
 *
 * Example:
 * intersectLists(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun intersectLists(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find and return a new list containing the elements that are present in both lists.
 *
 * @param list1 First list
 * @param list2 Second list
 * @return List of common elements
 *
 * Example:
 * intersectLists(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun intersectLists(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    for (elem in list1) {
        if (elem in list2) {
            commonElements.add(elem)
        }
    }
    return commonElements
}