Absolute PreBinaryS
IntuitionApproachComplexity

Time complexity:
O(nlog(n))


Space complexity:
O(n)

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

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

# Complexity
- Time complexity:
O(nlog(n))

- Space complexity:
O(n)

# Code
```javascript []
/**
 * @param {number[]} nums
 * @param {number[]} queries
 * @return {number[]}
 */
var minOperations = function (nums, queries) {
  nums.sort((a, b) => a - b);
  let pre = [];
  let sum = 0;
  let res = [];
  for (let n of nums) {
    sum += n;
    pre.push(sum);
  }
  for (let q of queries) {
    let left = 0;
    let right = nums.length;
    let pivot;

    while (left < right) {
      let mid = Math.floor((left + right) / 2);
      if (nums[mid] > q) {
        right = mid;
      } else {
        left = mid + 1;
      }
    }
    let t1 = q * left;
    let t2 = q * (nums.length - left);
    let c1 = pre[left - 1] || 0;
    let c2 = pre[pre.length - 1] - (pre[left - 1] || 0);
    res.push(Math.abs(t1 - c1) + Math.abs(t2 - c2));
  }
  return res;
};
```
['JavaScript']