#3727

Maximum Alternating Sum of Squares

medium · 61.2% accepted · 70 likes · top 61%

array · greedy · sorting

Description

You are given an integer array nums. You may rearrange the elements in any order.

The alternating score of an array arr is defined as:

- score = arr[0]2 - arr[1]2 + arr[2]2 - arr[3]2 + ...

Return an integer denoting the maximum possible alternating score of nums after rearranging its elements.

Solution