Array formed using sum of absolute differences of that element with all other elements | Function to return the new array private static List < Integer > ; Length of the arraylist ; Initialize the Arraylist ; Sum of absolute differences of element with all elements ; Initialize sum to 0 ; Add the value of sum to ans ; Return the final ans ; Driver Code ; Given array arr [ ] ; Function call
def calculate ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE ans = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE for j in range ( len ( arr ) ) : NEW_LINE INDENT sum += abs ( arr [ i ] - arr [ j ] ) NEW_LINE DEDENT ans . append ( sum ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 5 , 6 ] NEW_LINE print ( calculate ( arr ) ) NEW_LINE DEDENT