/**
 * Given two lists, find the intersection of elements present in both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements found in both lists.
 *
 * Example:
 * '``
 * val list1 = listOf(1, 2, 3, 4, 5)
 * val list2 = listOf(4, 5, 6, 7, 8)
 * println(findCommonElements(list1, list2)) // Output: [4, 5]
 * '``
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over each element in list1
    for (element in list1) {
        // Check if the element is present in list2
        if (element in list2) {
            // Append the common element to the commonElements list
            commonElements.add(element)
        }
    }

    return commonElements
}
/**
 * Given two lists, find the intersection of elements present in both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements found in both lists.
 *
 * Example:
 * '``
 * val list1 = listOf(1, 2, 3, 4, 5)
 * val list2 = listOf(4, 5, 6, 7, 8)
 * println(findCommonElements(list1, list2)) // Output: [4, 5]
 * '``
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find the intersection of elements present in both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements found in both lists.
 *
 * Example:
 * '``
 * val list1 = listOf(1, 2, 3, 4, 5)
 * val list2 = listOf(4, 5, 6, 7, 8)
 * println(findCommonElements(list1, list2)) // Output: [4, 5]
 * '``
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over each element in list1
    for (element in list1) {
        // Check if the element is present in list2
        if (element in list2) {
            // Append the common element to the commonElements list
            commonElements.add(element)
        }
    }

    return commonElements
}