CPP | Easy | Prefix Sum | Time O(QlogN)
Intuition : Sort the array and generate prefix sum for nums and for each query search for this sum using binary-search in your prefix-sum array\n\nTime complexi
**Intuition :** Sort the array and generate prefix sum for `nums` and for each query search for this sum using `binary-search` in your `prefix-sum` array\n\n**Time complexity :** `O(QlogN + NlogN)`\n**Space complexity :** `O(Q)`\n\n```\nclass Solution {\npublic:\n    vector<int> answerQueries(vector<int>& v, vector<int>& q) {\n        sort(v.begin(),v.end());\n        for(int i=1;i<v.size();i++)v[i]+=v[i-1];\n        vector<int> ans;\n        for(int x:q){\n            int idx=upper_bound(v.begin(),v.end(),x)-v.begin();\n            ans.push_back(idx);\n        }\n        return ans;\n    }\n};\n```
['Binary Tree', 'Prefix Sum', 'C++']