LeetCode Entry

1207. Unique Number of Occurrences

30.11.2022 easy 2022 kotlin

fun uniqueOccurrences(arr: IntArray): Boolean {

1207. Unique Number of Occurrences easy

https://t.me/leetcode_daily_unstoppable/36


fun uniqueOccurrences(arr: IntArray): Boolean {
	val counter = mutableMapOf<Int, Int>()
	arr.forEach { n -> counter[n] = 1 + (counter[n] ?: 0) }
	val freq = mutableSetOf<Int>()
	return !counter.values.any { count -> !freq.add(count) }
}

Nothing interesting, just count and filter.

O(N) time, O(N) space