Beginner Friendly | Brute Force
\n\n# Code\n\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        int n=queries.length;\n        int[] ans=new int[n];\n     
\n\n# Code\n```\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        int n=queries.length;\n        int[] ans=new int[n];\n        Arrays.sort(nums);\n        int sum=0;\n        int count=0;\n        for(int i=0;i<n;i++){\n            int flag=0;\n            for(int j=0;j<nums.length;j++){\n                if(sum+nums[j]<=queries[i]){\n                    sum+=nums[j];\n                    count++;\n                    \n                }\n                else{\n                    ans[i]=count;\n                    count=0;\n                    sum=0;\n                    flag=1;\n                    break;\n                }\n            }\n            if(flag==0){\n                ans[i]=count;\n                count=0;\n                sum=0;\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']