LeetCode Entry
2225. Find Players With Zero or One Losses
[sorted winners list, sorted single lose list]
2225. Find Players With Zero or One Losses medium
blog post
substack
youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/472
Problem TLDR
[sorted winners list, sorted single lose list]
Intuition
No special algorithms here, just a set manipulation.
Approach
Let’s use some Kotlin’s API:
- map
- groupingBy
- eachCount
- filter
- sorted
Complexity
-
Time complexity: \(O(nlog(n))\)
-
Space complexity: \(O(n)\)
Code
fun findWinners(matches: Array<IntArray>) = buildList {
val winners = matches.map { it[0] }.toSet()
val losers = matches.groupingBy { it[1] }.eachCount()
add((winners - losers.keys).sorted())
add(losers.filter { (k, v) -> v == 1 }.keys.sorted())
}