Simple Java Solution with Binary Search
\nTime Complexity- O(mlogn + n)\nSpace O(n)\n\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        int n = nums.length;\n    
\nTime Complexity- O(mlogn + n)\nSpace O(n)\n```\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n        int n = nums.length;\n        int m = queries.length;\n        \n        // Sorting array nums\n        Arrays.sort(nums);\n        \n        // Taking prefix sum\n        for(int i = 1; i < n; i++) {\n            nums[i] += nums[i - 1];\n        }\n        \n        int[] ans = new int[m];\n        for(int i = 0; i < m; i++) {\n            int q = queries[i];\n            \n            // performing binary search for each query\n            int low = 0, high = n - 1;\n            while(low <= high) {\n                int mid = low + (high - low) / 2;\n                if(nums[mid] == q) {\n                    ans[i] = mid + 1;\n                    break;\n                }\n                else if(nums[mid] < q) {\n                    ans[i] = mid + 1;\n                    low = mid + 1;\n                }\n                else {\n                    high = mid - 1;\n                }\n            }\n        }\n        \n        return ans;\n    }\n}\n```\nTime Complexity - O(m*n + nlogn)\n\n```\nclass Solution {\n    public int length(int[] arr,int n)\n    {\n        int sum=0,i=0;\n        for(i=0;i<arr.length;i++)\n        {\n            if(sum+arr[i]>n)\n            return i;\n            sum+=arr[i];\n        }\n        return i;\n    }\n    public int[] answerQueries(int[] nums, int[] queries) {\n        Arrays.sort(nums);\n        for(int i=0;i<queries.length;i++)\n        {\n            int n=length(nums,queries[i]);\n            queries[i]=n;\n        }\n        return queries;\n    }\n}
['Java']