Created
February 3, 2021 05:48
-
-
Save imhardiklakhani/9e5085f39a7b07b1350d195a951e6dcd to your computer and use it in GitHub Desktop.
Find Duplicate Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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