Kotlin | Count Array
Intuition & ApproachJust read my comment at the topComplexity

Time complexity:
O(n) where n is the size of nums


Space complexity:
O(1)

Code
# Intuition & Approach
Just read my comment at the top

# Complexity
- Time complexity:
$$O(n)$$ where n is the size of nums

- Space complexity:
$$O(1)$$

# Code
```kotlin []
class Solution {
    fun getLargestOutlier(nums: IntArray): Int {
        // Plan: Sum all the numbers, try removing each number in turn from largest to smallest. 
        // See if the remainder is equal to 2 * one of the remaining values in it.
        // Change of plan: List isn't sorted, it'd be nlogn to sort descending so we can stop at first found, 
        // as opposed to n to simply check every item in the list. Let's do that instead
        // Also the range for nums is only 2001, so we can keep an array instead of a map
        // val counts = nums.asList().groupingBy { it }.eachCount()
        val counts = IntArray(2001)
        val sum = nums.sum()
        var max = Integer.MIN_VALUE

        for (num in nums) {
            counts[num + 1000]++
        }

        for (num in nums) {
            // Check that it divides evenly
            if (abs(sum - num) % 2 == 1) continue
            val target = (sum - num) / 2
            if (target < -1000 || target > 1000) continue // Prevent ArrayIndexOutOfBounds
            val count = counts[target + 1000] // ?: 0
            if (target == num) {
                if (count > 1) max = maxOf(max, num)
            } else {
                if (count > 0) max = maxOf(max, num)
            }
        }

        return max
    }
}
```
['Kotlin']