Skip to content

Instantly share code, notes, and snippets.

@imhardiklakhani
Created February 3, 2021 05:48
Show Gist options
  • Save imhardiklakhani/9e5085f39a7b07b1350d195a951e6dcd to your computer and use it in GitHub Desktop.
Save imhardiklakhani/9e5085f39a7b07b1350d195a951e6dcd to your computer and use it in GitHub Desktop.
Find Duplicate Number
import java.util.*
// How do you find the duplicate number on a given integer array?
fun main() {
val arr = arrayListOf(4, 5, 8, 3, 4, 11,5,8, 15, 3,4,4)
println(arr.groupingBy {
it
}.eachCount().filter{
it.value>1
})
}
/*
OUTPUT:
{4=4, 5=2, 8=2, 3=2}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment