𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 | D𝗲𝘁𝗮𝗶𝗹𝗲𝗱 VIDEO 𝗲𝘅𝗽𝗹𝗮𝗻𝗮𝘁𝗶𝗼𝗻 | Binary Search
Intuition & Approach\n Describe your approach to solving the problem. \n\n\u2028\uD835\uDDE3\uD835\uDDF9\uD835\uDDF2\uD835\uDDEE\uD835\uDE00\uD835\uDDF2 \uD835\
# Intuition & Approach\n<!-- Describe your approach to solving the problem. -->\n\n\u2028\uD835\uDDE3\uD835\uDDF9\uD835\uDDF2\uD835\uDDEE\uD835\uDE00\uD835\uDDF2 \uD835\uDDF1\uD835\uDDFF\uD835\uDDFC\uD835\uDDFD \uD835\uDDF0\uD835\uDDFC\uD835\uDDFA\uD835\uDDFA\uD835\uDDF2\uD835\uDDFB\uD835\uDE01\uD835\uDE00 \uD835\uDDEE\uD835\uDDFB\uD835\uDDF1 \uD835\uDDF3\uD835\uDDF2\uD835\uDDF2\uD835\uDDF1\uD835\uDDEF\uD835\uDDEE\uD835\uDDF0\uD835\uDDF8 \uD835\uDDF3\uD835\uDDFC\uD835\uDDFF \uD835\uDDF6\uD835\uDDFA\uD835\uDDFD\uD835\uDDFF\uD835\uDDFC\uD835\uDE03\uD835\uDDF2\uD835\uDDFA\uD835\uDDF2\uD835\uDDFB\uD835\uDE01\nhttps://youtu.be/TeRpWGScPbo\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn+mlogn) = O((m+n)logn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\n/**\n * @param {number[]} nums\n * @param {number[]} queries\n * @return {number[]}\n */\nvar answerQueries = function(nums, queries) {\n    let n = nums.length\n    nums.sort((a,b)=>a-b)\n    let preSum = new Array()\n    preSum.push(nums[0])\n    for (let i = 1; i < n; i++) {\n        preSum.push(nums[i]+preSum[i-1])\n    }\n\n    let bs = function(l, r, target) {\n        while (l < r) {\n            let m = Math.ceil((l+r)/2)\n            if (preSum[m] <= target) l = m\n            else r = m - 1\n        }\n        return l+1\n    }\n\n    let answer = new Array()\n    for (let q of queries) {\n        let ans = 0\n        if (q >= preSum[0]) ans = bs(0,n-1, q)\n        answer.push(ans)\n    }\n    return answer\n};\n```
['JavaScript']