Ball Arrangement for Maximum Engagement ๐พ
In a content creator challenge, a user with a bag of balls, each labeled with different numerical values, aims to arrange the balls in a circle to create a video with the highest level of engagement.
Formally, you are provided an array values representing the attributes of each ball. The objective is to arrange these elements in a circle. You have the creative freedom to determine the order in which the elements are positioned in the circle, and you can insert each element at any location within the circle.
The level of engagement for a particular arrangement is calculated as follows:
The challenge involves finding the arrangement that results in the highest total engagement and producing a TikTok video that captivates the audience.
Complete the function findMaximumEngagement in the editor below.
findMaximumEngagement has the following parameters:
int values[n]: an array of integers
Returns
long: maximum total engagement that can be achieved overall arrangements
1Example 1

Constraints
Limits and guarantees your solution can rely on.
- 2 โค n โค 2*105
There must be some other constrainsts that we haven't found