Easiest solution using iteration
\n# Code\n\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        \n        int[] ans = new int[queries.length];\n        Array
\n# Code\n```\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        \n        int[] ans = new int[queries.length];\n        Arrays.sort(nums);\n\n        for(int i=0;i<queries.length;i++){\n            int sum=0;\n            int j=0;\n            while(sum<=queries[i]){\n                if(j == nums.length){\n                    j++;\n                    break;\n                }\n                sum += nums[j];\n                j++;\n            }\n            ans[i] = j-1;\n        }\n        return ans;\n        \n    }\n}\n```
['Java']