Beats 100% || Binary Search and Prefix Sum algo EASY
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int[] answerQueries(int[] nums, int[] queries) {

         int n=queries.length;

    int[] ans = new int[n];

    Arrays.sort(nums);

    for(int i=1;i<nums.length;i++){
    nums[i]+= nums[i-1];
    }

    for(int i=0;i<n;i++){
      int left = 0, right = nums.length-1;
      while(left<=right){
        int mid = left +(right-left)/2;

        if(nums[mid] > queries[i]){
            right=mid-1;
        }else{
            left=mid+1;
        }

      }
      ans[i]=left;
    }
return ans;
    }
}
```
['Java']