/**
 * Given two arrays of integers, find the common elements present in both arrays.
 *
 * @param array1 the first array of integers
 * @param array2 the second array of integers
 * @return a list of integers representing the common elements
 *
 * Example:
 * findDuplicates(intArrayOf(1, 2, 3, 4, 5), intArrayOf(4, 5, 6, 7, 8))
 * Output: [4, 5]
 */
fun findDuplicates(array1: IntArray, array2: IntArray): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over each element in array1
    for (element1 in array1) {
        // Iterate over each element in array2
        for (element2 in array2) {
            // Check if the current element in array1 is equal to the current element in array2
            if (element1 == element2) {
                // Check if the current element is not already in commonElements list
                if (!commonElements.contains(element1)) {
                    // Add the common element to the list
                    commonElements.add(element1)
                }
            }
        }
    }

    return commonElements
}
/**
 * Given two arrays of integers, find the common elements present in both arrays.
 *
 * @param array1 the first array of integers
 * @param array2 the second array of integers
 * @return a list of integers representing the common elements
 *
 * Example:
 * findDuplicates(intArrayOf(1, 2, 3, 4, 5), intArrayOf(4, 5, 6, 7, 8))
 * Output: [4, 5]
 */
fun findDuplicates(array1: IntArray, array2: IntArray): List<Int> {
/**
 * Given two arrays of integers, find the common elements present in both arrays.
 *
 * @param array1 the first array of integers
 * @param array2 the second array of integers
 * @return a list of integers representing the common elements
 *
 * Example:
 * findDuplicates(intArrayOf(1, 2, 3, 4, 5), intArrayOf(4, 5, 6, 7, 8))
 * Output: [4, 5]
 */
fun findDuplicates(array1: IntArray, array2: IntArray): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over each element in array1
    for (element1 in array1) {
        // Iterate over each element in array2
        for (element2 in array2) {
            // Check if the current element in array1 is equal to the current element in array2
            if (element1 == element2) {
                // Check if the current element is not already in commonElements list
                if (!commonElements.contains(element1)) {
                    // Add the common element to the list
                    commonElements.add(element1)
                }
            }
        }
    }

    return commonElements
}