Java || Sorting + Prefix Sum + Binary Search
Complexity\n- Time complexity: O((m+n)logn)\n\n- Space complexity: O(n)\n\n## Code\njava []\nclass Solution {\n    public List<Long> minOperations(int[] nums, i
## Complexity\n- Time complexity: O((m+n)logn)\n\n- Space complexity: O(n)\n\n## Code\n``` java []\nclass Solution {\n    public List<Long> minOperations(int[] nums, int[] queries) {\n        Arrays.sort(nums);\n        List<Long> list = new ArrayList<>();\n        long[] prefix = new long[nums.length+2]; // taking prefix[0] an prefix[prefix.length-1] as 0 to avoid Index Out Of Bound\n        long sum=0;\n        for(int i=0;i<nums.length;i++){\n            sum+=nums[i];\n            prefix[i+1]=sum;\n        }\n        for(int x:queries){\n            int idx = Arrays.binarySearch(nums,x);\n            if(idx<0){\n                idx = -1*(idx+2);\n            }\n            list.add(((long)(idx+1)*x - prefix[idx+1]) + ((prefix[prefix.length-2] - prefix[idx+1]) - (long)(nums.length - idx - 1)*x));\n        }\n        return list;\n    }\n}\n```
['Binary Search', 'Sorting', 'Prefix Sum', 'Java']