Explanation: Let’s an arrray A[4]={1, 4, 3, 5}. According to given function, SUM: = (1-4)+(1-3)+(1-5)+(4-3)+(4-5)+(3-5) = 1-4+1-3+1-5+4-3+4-5+3-5 = 1+1+1+4+4+3-4-3-3-5-5-5 = (1×3)+(4×2)+(3×1)-(4×1)-(3×2)-(5×3) = ? Isn’t easy to get SUM from the array? Here is the code to get SUM: So, for…
1st Approach: Brute Force; 2nd Approach: Implementation; #Faster Method