[Kotlin]Double binary search
binary search answer\n2. For each answer p, find out the number (product >= p). (iterate first array and binary search the second array)\n\n\n/**\n * Double bin
1. binary search answer\n2. For each answer p, find out the number (product >= p). (iterate first array and binary search the second array)\n\n```\n/**\n * Double binary search\n */\nfun kthSmallestProduct(nums1: IntArray, nums2: IntArray, k: Long): Long {\n\n    val orderNums2 = nums2.toList()\n    val reversedNums2 = nums2.reversed()\n    fun doGetLessEqual(a: Long, p: Long, nums: List<Int>): Long {\n        if (a * nums.first() > p) return 0\n\n        var l = 0\n        var r = nums.size\n        while (l < r) {\n            val m = (l + r) / 2\n            if (a * nums[m] > p) r = m\n            else l = m + 1\n        }\n        return 1L * l\n    }\n\n    fun getLessEqual(a: Long, p: Long): Long {\n        if (a > 0) return doGetLessEqual(a, p, orderNums2)\n        if (a < 0) return doGetLessEqual(a, p, reversedNums2)\n\n        return if (p >= 0) 1L * nums2.size else 0\n    }\n\n\n    // min and max will be in this list.\n    val limits = listOf(\n        1L * nums1[0] * nums2[0],\n        1L * nums1[0] * nums2.last(),\n        1L * nums1.last() * nums2[0],\n        1L * nums1.last() * nums2.last()\n    )\n    var l = limits.min()!!\n    var r = limits.max()!!\n    while (l < r) {\n        val m = l + (r - l) / 2\n\n        var lessEqualCnt = nums1.map { getLessEqual(1L * it, m) }.sum()\n        if (lessEqualCnt >= k) r = m\n        else l = m + 1\n    }\n\n    return l\n}\n\n```
[]