package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array/
 */
public class Problem1685 {
    public int[] getSumAbsoluteDifferences(int[] nums) {
        int[] answer = new int[nums.length];
        // TODO
        return answer;
    }

    public static void main(String[] args) {
        Problem1685 prob = new Problem1685();
        System.out.println(Arrays.toString(prob.getSumAbsoluteDifferences(new int[]{1,2,3}))); // [3,2,3]
        System.out.println(Arrays.toString(prob.getSumAbsoluteDifferences(new int[]{2,3,5}))); // [4,3,5]
        System.out.println(Arrays.toString(prob.getSumAbsoluteDifferences(new int[]{1,2,3,4,5}))); // [10,7,6,7,10]
        System.out.println(Arrays.toString(prob.getSumAbsoluteDifferences(new int[]{1,4,6,8,10}))); // [24,15,13,15,21]
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -198,22 +198,26 @@
   int%5B%5D 
-answer
+prefixSums
  = new i
@@ -245,584 +245,610 @@
     
-// TODO%0A        return answer
+int totalSum = 0;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            totalSum += nums%5Bi%5D
 ;%0A    
-%7D%0A%0A
+    
     p
-ublic static void main(String%5B%5D args) %7B%0A        Problem1685 prob = new Problem1685();%0A        System.out.println(Arrays.toString(prob.getSumAbsoluteDifferences(new int%5B%5D%7B1,2,3%7D))); // %5B3,2,3%5D%0A        System.out.println(Arrays.toString(prob.getSumAbsoluteDifferences(new int%5B%5D%7B2,3,5%7D))); // %5B4,3,5%5D%0A        System.out.println(Arrays.toString(prob.getSumAbsoluteDifferences(new int%5B%5D%7B1,2,3,4,5%7D))); // %5B10,7,6,7,10%5D%0A        System.out.println(Arrays.toString(prob.getSumAbsoluteDifferences(new int%5B%5D%7B1,4,6,8,10%7D))); // %5B24,15,13,15,21%5D
+refixSums%5Bi%5D = (i %3E 0 ? prefixSums%5Bi - 1%5D : 0) + nums%5Bi%5D;%0A        %7D%0A        int%5B%5D answer = new int%5Bnums.length%5D;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            int sumLeft = (i - 1 %3E= 0 ? prefixSums%5Bi - 1%5D : 0);%0A            int sumAbsLeft = (i * nums%5Bi%5D) - sumLeft;%0A            int sumRight = totalSum - prefixSums%5Bi%5D;%0A            int sumAbsRight = sumRight - ((nums.length - i - 1) * nums%5Bi%5D);%0A            answer%5Bi%5D = sumAbsLeft + sumAbsRight;%0A        %7D%0A        return answer;
 %0A   

Update problem 1685