-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIteration1.kt
More file actions
26 lines (21 loc) · 741 Bytes
/
Iteration1.kt
File metadata and controls
26 lines (21 loc) · 741 Bytes
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
fun missingNumbers(arr: Array<Int>, brr: Array<Int>): Set<Int> {
val map = mutableMapOf<Int, Int>()
for (i in brr) map[i] = (map[i] ?: 0) + 1
for (i in arr) {
map[i] = (map[i] ?: 1) - 1
if ((map[i] ?: 0) == 0) map.remove(i)
}
return map.keys.toSortedSet()
}
fun main() {
readLine()
val arr = readLine()!!.trimEnd().split(" ").map { it.toInt() }.toTypedArray()
readLine()
val brr = readLine()!!.trimEnd().split(" ").map { it.toInt() }.toTypedArray()
println(missingNumbers(arr, brr).joinToString(" "))
}
/**
* Store all the frequencies of brr in a map.
* Reduce from them by checking the arr.
* If the frequency becomes 0, it means that element is not missing in the arr.
* */