Easy Java Solution || Sort
\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        int[] ans=new int[queries.length];\n        //If length of arry is 0 re
```\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        int[] ans=new int[queries.length];\n        //If length of arry is 0 returning the array\n        if(nums.length==0){\n            return ans;\n        }\n        //Sorting the array\n        Arrays.sort(nums);\n        //Creating a sumarray to store the sum of subarray\n        int[] sumarray=new int[nums.length];   \n        sumarray[0]=nums[0];\n        for(int i=1;i<nums.length;i++){\n            sumarray[i]=nums[i]+sumarray[i-1];\n        }\n        //Iterating over queries\n        for(int i=0;i<queries.length;i++){\n            int start=0;\n            int end=sumarray.length-1;\n            //Binary search to find element less then or equal to the query and maximum size\n            while(start<=end){\n                int mid=start+(end-start)/2;\n                if(sumarray[mid]==queries[i]){\n                    ans[i]=mid+1;\n                    break;\n                }\n                else if(sumarray[mid]>queries[i]){\n                    end=mid-1;\n                }\n                else{\n                    ans[i]=mid+1;\n                    start=mid+1;\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Sorting', 'Java']