https://leetcode.com/problems/distribute-candies/description/ Easy

Решение

class Solution {
    fun distributeCandies(candyType: IntArray): Int {
        val n = candyType.size
        val limit = n ushr 1
        val seen = BooleanArray(200001)
        val off = 100000
        var kinds = 0
        var i = 0
        while (i < n && kinds < limit) {
            val idx = candyType[i] + off
            if (!seen[idx]) {
                seen[idx] = true
                kinds++
            }
            i++
        }
        return kinds
    }
}