Description
Solutions
Submission
Ball Arrangement for Maximum Engagement 🐾
🔥 FULLTIME🤘 INTERN

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 first element placed in the circle contributes 0 to the engagement.
  • For each subsequent element placed, its contribution is equal to the smaller of the numerical values of the elements to its left and right.
  • The challenge involves finding the arrangement that results in the highest total engagement and producing a TikTok video that captivates the audience.

    Function Description

    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

    Example 1:

    Input:  values = [1, 3, 5, 3, 2]
    Output: 14
    Explanation:
    A possible arrangement which gives maximum total engagement = 14 is shown: - The latest element arranged is highlighted in red. - The smaller values on the left and right of the highlighted element are added to the total engagement in each step.
    Constraints:
      • 2 ≤ n ≤ 2*105
      • There must be some other constrainsts that we haven't found
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: