/**
 * Given two lists, find the elements that are present in both lists and return them as a new list.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the elements that are present in both lists.
 *
 * Example:
 * findSimilarElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) => [4, 5]
 */
fun findSimilarElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val similarElements = mutableListOf<Int>()

    list1.forEach { element ->
        if (element in list2 && element !in similarElements) {
            similarElements.add(element)
        }
    }

    return similarElements
}
/**
 * Given two lists, find the elements that are present in both lists and return them as a new list.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the elements that are present in both lists.
 *
 * Example:
 * findSimilarElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) => [4, 5]
 */
fun findSimilarElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find the elements that are present in both lists and return them as a new list.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the elements that are present in both lists.
 *
 * Example:
 * findSimilarElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) => [4, 5]
 */
fun findSimilarElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val similarElements = mutableListOf<Int>()

    list1.forEach { element ->
        if (element in list2 && element !in similarElements) {
            similarElements.add(element)
        }
    }

    return similarElements
}