✅✅Faster || Easy To Understand || C++ Code
Using Sorting && Prefix Sum && Binary Search\n\n Time Complexity :- O(NlogN)\n\n Space Complexity :- O(1)\n\n\nclass Solution {\npublic:\n   \n    vector<int> a
* ***Using Sorting && Prefix Sum && Binary Search***\n\n* ***Time Complexity :- O(NlogN)***\n\n* ***Space Complexity :- O(1)***\n\n```\nclass Solution {\npublic:\n   \n    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {\n        \n        int n = queries.size();\n        \n        // sort the array, because order will not matter\n        \n        sort(nums.begin(), nums.end());\n        \n        // find the prefix sum\n        \n        for(int i = 1; i < nums.size(); i++)\n        {\n            nums[i] += nums[i - 1];\n        }\n        \n        // res[i] will store the answer of each query\n       \n        vector<int> res(n);\n        \n        // solve for each query\n        \n        for(int i = 0; i < n; i++)\n        {\n            // find the upper bound of sum\n            \n            int idx = upper_bound(nums.begin(), nums.end(), queries[i]) - nums.begin();\n            \n            res[i] = idx;\n        }\n        \n        return res;\n    }\n};\n```
['Binary Search', 'C', 'Sorting', 'Prefix Sum', 'C++']