Write a kotlin program to find common elements between two arrays

Write a program to identify common elements or numbers between two given arrays. You should not use any inbuilt methods are list to find common values.

Kotlin program to find common elements between two arrays

fun main(a: Array<String>) {
    val arr1 = intArrayOf(4, 7, 3, 9, 2)
    val arr2 = intArrayOf(3, 2, 12, 9, 40, 32, 4)
    for (i in arr1.indices) {
        for (j in arr2.indices) {
            if (arr1[i] == arr2[j]) {
                println(arr1[i])
            }
        }
    }
}


Output

4
3
9
2
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions