/**
 * Given two lists, list1 and list2, implement the following logic:
 * - If list1 and list2 are both empty, return an empty list.
 * - If list1 is empty and list2 is not empty, return a copy of list2.
 * - If list1 is not empty and list2 is empty, return a copy of list1.
 * - Otherwise, return a list that contains the elements that are present in both list1 and list2,
 *   in the same order they appear in list1.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return The resulting list based on the given conditions.
 */
fun conditionalCopyList(list1: List<Any>, list2: List<Any>): List<Any> {

    if (list1.isEmpty() && list2.isEmpty()) {
        return emptyList()  // If list1 and list2 are both empty, return an empty list.
    }

    if (list1.isEmpty() && list2.isNotEmpty()) {
        return list2.toList()  // If list1 is empty and list2 is not empty, return a copy of list2.
    }

    if (list1.isNotEmpty() && list2.isEmpty()) {
        return list1.toList()  // If list1 is not empty and list2 is empty, return a copy of list1.
    }

    return list1.filter { it in list2 }  // Return a list containing elements present in both lists.
}
/**
 * Given two lists, list1 and list2, implement the following logic:
 * - If list1 and list2 are both empty, return an empty list.
 * - If list1 is empty and list2 is not empty, return a copy of list2.
 * - If list1 is not empty and list2 is empty, return a copy of list1.
 * - Otherwise, return a list that contains the elements that are present in both list1 and list2,
 *   in the same order they appear in list1.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return The resulting list based on the given conditions.
 */
fun conditionalCopyList(list1: List<Any>, list2: List<Any>): List<Any> {
/**
 * Given two lists, list1 and list2, implement the following logic:
 * - If list1 and list2 are both empty, return an empty list.
 * - If list1 is empty and list2 is not empty, return a copy of list2.
 * - If list1 is not empty and list2 is empty, return a copy of list1.
 * - Otherwise, return a list that contains the elements that are present in both list1 and list2,
 *   in the same order they appear in list1.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return The resulting list based on the given conditions.
 */
fun conditionalCopyList(list1: List<Any>, list2: List<Any>): List<Any> {

    if (list1.isEmpty() && list2.isEmpty()) {
        return emptyList()  // If list1 and list2 are both empty, return an empty list.
    }

    if (list1.isEmpty() && list2.isNotEmpty()) {
        return list2.toList()  // If list1 is empty and list2 is not empty, return a copy of list2.
    }

    if (list1.isNotEmpty() && list2.isEmpty()) {
        return list1.toList()  // If list1 is not empty and list2 is empty, return a copy of list1.
    }

    return list1.filter { it in list2 }  // Return a list containing elements present in both lists.
}