/**
 * Imagine you are an archaeologist studying ancient artifacts. You have two crates of artifacts, each containing several objects.
 * Your task is to find the common elements between the two crates.
 *
 * Implement a function called 'findCommonElements' that takes in two lists as arguments, 'list1' and 'list2'.
 * The function should return a list containing all the elements that are present in both 'list1' and 'list2'.
 *
 * Your solution should NOT use any built-in intersection or set functions.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over list1 to find elements present in list2
    for (item in list1) {
        if (list2.contains(item)) {
            commonElements.add(item)
        }
    }

    // Return the list of common elements
    return commonElements
}
/**
 * Imagine you are an archaeologist studying ancient artifacts. You have two crates of artifacts, each containing several objects.
 * Your task is to find the common elements between the two crates.
 *
 * Implement a function called 'findCommonElements' that takes in two lists as arguments, 'list1' and 'list2'.
 * The function should return a list containing all the elements that are present in both 'list1' and 'list2'.
 *
 * Your solution should NOT use any built-in intersection or set functions.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Imagine you are an archaeologist studying ancient artifacts. You have two crates of artifacts, each containing several objects.
 * Your task is to find the common elements between the two crates.
 *
 * Implement a function called 'findCommonElements' that takes in two lists as arguments, 'list1' and 'list2'.
 * The function should return a list containing all the elements that are present in both 'list1' and 'list2'.
 *
 * Your solution should NOT use any built-in intersection or set functions.
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) -> [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over list1 to find elements present in list2
    for (item in list1) {
        if (list2.contains(item)) {
            commonElements.add(item)
        }
    }

    // Return the list of common elements
    return commonElements
}