✅[C++] (BRUTE FORCE ) Is it difficult (should be in medium)? Prefix sum Lower_Bound || Easy
Please UPVOTE if you think it should in medium level not in easy!! \nit contains sorting + prefix sum + Binary Search (i guess it is fit for medium level)\n\ncl
Please UPVOTE if you think it should in medium level not in easy!! \nit contains sorting + prefix sum + Binary Search (i guess it is fit for medium level)\n```\nclass Solution \n{\npublic:\n   vector<int> answerQueries(vector<int>& nums, vector<int>& q) {\n        int n=nums.size();\n        int m=q.size();\n        sort(nums.begin(),nums.end());\n        \n        vector<int> v;\n        \n        vector<int> pre(n+1,0);\n        for(int i=1;i<n+1;i++)\n        {\n            pre[i]=pre[i-1]+nums[i-1];\n        }\n                                       // dekh rahe hai kitno ka totalsum hamare queries[i] se chhota hai\n        for(int i=0;i<m;i++)\n        {\n            int sum=q[i];\n            auto  z=lower_bound(pre.begin(),pre.end(),sum)-pre.begin();\n            if(z<n+1)\n            {\n                if(pre[z]==sum)\n                    v.push_back(z);\n                else \n                    v.push_back(z-1);\n            }\n            else if(z==n+1)\n                v.push_back(n);\n        }\n        return v;\n    }\n};\n```
['Binary Search', 'C', 'Prefix Sum']