From Brute Force to Binary Search
Java Brutal Force\n\njava\npublic int[] answerQueries(int[] nums, int[] queries) {\n        Arrays.sort(nums);\n\t\tint[] result = new int[queries.length];\n   
##### *Java Brutal Force*\n\n```java\npublic int[] answerQueries(int[] nums, int[] queries) {\n        Arrays.sort(nums);\n\t\tint[] result = new int[queries.length];\n        \n        for (int i = 0, count = 0, sum = 0, j = 0; i < queries.length; ++i, count = 0, sum = 0, j = 0) {\n            while (j < nums.length && sum + nums[j] <= queries[i]) {\n                sum += nums[j++];\n                count++;\n            }\n            result[i] = count;\n        }\n        return result;\n    }\n```\n\n##### *C++ Brutal Force*\n\n```c++\npublic:\n    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {\n        sort(nums.begin(), nums.end());\n        vector<int> result(queries.size());\n        \n        for (int i = 0, count = 0, sum = 0, j = 0; i < queries.size(); ++i, count = 0, sum = 0, j = 0) {\n            while (j < nums.size() && sum + nums[j] <= queries[i]) {\n                sum += nums[j++];\n                count++;\n            }\n            result[i] = count;\n        }\n        return result;\n    }\n```\n\n##### *Java Prefix Sum*\n```java\npublic int[] answerQueries(int[] nums, int[] queries) {\n        Arrays.sort(nums);\n        TreeMap<Integer, Integer> treeMap = createTreeMap(nums);\n        int[] result = new int[queries.length];\n        \n        for (int i = 0; i < queries.length; ++i) {\n            Integer floorKey = treeMap.floorKey(queries[i]);\n            if (floorKey != null)\n                result[i] = treeMap.get(floorKey);\n        }\n\n        return result;\n    }\n    \n    private TreeMap<Integer, Integer> createTreeMap(int[] nums) {\n        TreeMap<Integer, Integer> treeMap = new TreeMap<>();\n        \n        for (int i = 0, sum = 0; i < nums.length; ++i) {\n            sum += nums[i];\n            treeMap.put(sum, i + 1);\n        }\n        \n        return treeMap;\n    }\n```\n##### *C++ Prefix Sum*\n```c++\npublic:\n    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {\n        sort(nums.begin(), nums.end());\n        toPrefixSum(nums);\n        vector<int> result;\n        \n        for (int i = 0; i < queries.size(); ++i) {\n            int count = upper_bound(nums.begin(), nums.end(), queries[i]) - nums.begin();\n            result.push_back(count);\n        }\n\n        return result;\n    }\n    \nprivate:\n    void toPrefixSum(vector<int>& nums) {  \n        for (int i = 1; i < nums.size(); ++i) \n            nums[i] = nums[i - 1] + nums[i];\n    }\n```
['C', 'Java']