Kotlin. Beats 100% (205 ms). Bit masks solution.
\n\n# Code\n\nclass Solution {\n    fun findMaxK(nums: IntArray): Int {\n        val counters = IntArray(1024)\n        var max = -1\n        for (n in nums) {\
![image.png](https://assets.leetcode.com/users/images/eb45bdb1-1cc2-4185-b849-a92fcd93d202_1714631913.012272.png)\n\n# Code\n```\nclass Solution {\n    fun findMaxK(nums: IntArray): Int {\n        val counters = IntArray(1024)\n        var max = -1\n        for (n in nums) {\n            val an = Math.abs(n)\n            counters[an] = counters[an] or if (n < 0) 1 else 2\n            if (counters[an] == 3) {\n                max = Math.max(max, an)\n            }\n        }\n        return max\n    }\n}\n```\n\n# Alternative approach\n\nSolution with two boolean arrays is also possible.\n\n![image.png](https://assets.leetcode.com/users/images/44400810-eb7e-4850-bb48-17c35e765c5f_1714632170.7192981.png)\n\n```\nclass Solution {\n    fun findMaxK(nums: IntArray): Int {\n        val neg = BooleanArray(1024)\n        val pos = BooleanArray(1024)\n        var max = -1\n        for (n in nums) {\n            val an = Math.abs(n)\n            if (n < 0) {\n                if (pos[an]) max = Math.max(max, an) else neg[an] = true\n            } else {\n                if (neg[an]) max = Math.max(max, an) else pos[an] = true\n            }\n        }\n        return max\n    }\n}\n```\n
['Kotlin']