/**
 * This function takes two lists as input and returns a new list containing common elements between the two lists.
 *
 * @param list1 A list of items (e.g., integers, strings, objects).
 * @param list2 A list of items (e.g., integers, strings, objects).
 * @return A list containing common elements found in both list1 and list2.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()
    for (item1 in list1) {
        for (item2 in list2) {
            if (item1 == item2) {
                commonElements.add(item1)
            } else if (item1 is List<*> && item2 is List<*>) {
                val nestedCommonElements = findCommonElements(item1 as List<Any>, item2 as List<Any>)
                commonElements.addAll(nestedCommonElements)
            }
        }
    }
    return commonElements
}
/**
 * This function takes two lists as input and returns a new list containing common elements between the two lists.
 *
 * @param list1 A list of items (e.g., integers, strings, objects).
 * @param list2 A list of items (e.g., integers, strings, objects).
 * @return A list containing common elements found in both list1 and list2.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {
/**
 * This function takes two lists as input and returns a new list containing common elements between the two lists.
 *
 * @param list1 A list of items (e.g., integers, strings, objects).
 * @param list2 A list of items (e.g., integers, strings, objects).
 * @return A list containing common elements found in both list1 and list2.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()
    for (item1 in list1) {
        for (item2 in list2) {
            if (item1 == item2) {
                commonElements.add(item1)
            } else if (item1 is List<*> && item2 is List<*>) {
                val nestedCommonElements = findCommonElements(item1 as List<Any>, item2 as List<Any>)
                commonElements.addAll(nestedCommonElements)
            }
        }
    }
    return commonElements
}