BEATS 63% using prefixSumm & binarySearch
Code
# Code
```java []
class Solution {

    public List<Long> minOperations(int[] nums, int[] queries) {
        int n = nums.length;
        Arrays.sort(nums);
        long[] prefixArr = new long[n + 1];
        for (int i = 0; i < n; i++) {
            prefixArr[i + 1] = nums[i] + prefixArr[i];
        }
        List<Long> result = new ArrayList<>();
        for (int target : queries) {
            int left = 0;
            int right = n - 1;
            while (left < right) {
                int mid = (left + right) / 2;
                if (nums[mid] >= target + 1) {
                    right = mid;
                } else left = mid + 1;
            }
            long posDiff = Math.abs(nums[left] - target);
            long beforePos = (long) target * (left) - prefixArr[left];
            long afterPos = (prefixArr[n] - prefixArr[left + 1]) - (long) target * (n - left - 1);
            result.add(posDiff + beforePos + afterPos);
        }
        return result;
    }
}
```
['Java']