Fast | Easy | Java
Code\n\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        int len = nums.length - 1;\n        int sum = 0;\n       Arrays.s
# Code\n```\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        int len = nums.length - 1;\n        int sum = 0;\n       Arrays.sort(nums);\n       for(int i = 0; i<=len; i++){\n           sum+=nums[i];\n           nums[i] = sum;\n       }\n       for(int i = 0; i<queries.length; i++){\n           int x = queries[i];\n//Binary Search Starts\n            int left = 0; int right = len; int mid = 0;\n            if(x<nums[left]){\n                queries[i] = left;\n                continue;\n            }\n             if(x>nums[right]){\n               queries[i] = right+1;\n                continue;\n            }\n            while(left<=right){\n                mid = left+(right-left)/2;\n                if(nums[mid]==x)break;\n                if(nums[mid]<x&&nums[mid+1]>x)break;\n                if(nums[mid]<x)left = mid+1;\n                if(nums[mid]>x)right = mid-1;\n            }\n            queries[i] = mid+1;\n//Binary Search ends.\n       }\n       return queries;\n    }\n}\n```
['Java']