-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolution.kt
49 lines (42 loc) · 1.14 KB
/
solution.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Sales by Match
*
* @author Dela Anthonio
* @hackerrank https://hackerrank.com/delaanthonio
* @problem https://www.hackerrank.com/challenges/sock-merchant
*/
import java.io.*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.functions.*
import kotlin.jvm.internal.*
import kotlin.ranges.*
import kotlin.sequences.*
import kotlin.text.*
// Complete the sockMerchant function below.
fun sockMerchant(n: Int, array: Array<Int>): Int {
var map = hashMap()
for (x in array) {
val count = map.getOrElse(x, 0)
map.put(x, count + 1)
}
val counts = map.values.map(x -> x / 2)
counts.foldRight(x,y -> x + y)
}
fun main(args: Array<String>) {
val scan = Scanner(System.`in`)
val n = scan.nextLine().trim().toInt()
val array = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
val result = sockMerchant(n, array)
println(result)
}