Missing Numbers

  • + 0 comments

    Kotlin

    fun missingNumbers(arr: Array<Int>, brr: Array<Int>): List<Int> {
        val countMap = brr.groupingBy { it }.eachCount().toMutableMap()
    
        arr.forEach { y ->
            countMap[y]?.let { count ->
                if (count > 1) countMap[y] = count - 1 else countMap.remove(y)
            }
        }
    
        return countMap.keys.sorted()
    }