[Kotlin] Binary search
\nimport kotlin.math.ceil\n\nclass Solution {\n    fun successfulPairs(spells: IntArray, potions: IntArray, success: Long): IntArray {\n    val res = IntArray(s
```\nimport kotlin.math.ceil\n\nclass Solution {\n    fun successfulPairs(spells: IntArray, potions: IntArray, success: Long): IntArray {\n    val res = IntArray(spells.size)\n    potions.sort()\n\n    fun findIndex(target: Long): Int {\n        var lo = 0\n        var hi = potions.lastIndex\n\n        while (lo < hi) {\n            val mid = lo + (hi - lo) / 2\n            if (potions[mid] >= target) hi = mid else lo = mid + 1\n        }\n        return hi\n    }\n\n    for (i in spells.indices) {\n        val target = ceil(success / spells[i].toDouble()).toLong()\n        if (potions.last() < target) continue\n        res[i] = potions.lastIndex - findIndex(target = target) + 1\n    }\n\n    return res\n}\n}\n```\n\n___\nTime: O(n*logn) - cost for sort\nSpace: O(n) - cost of result array\n___\n\n\n\n
['Binary Search', 'Kotlin']