Calculate Beauty Values
Given an array arr of size n and pairs of size m * 2,
where each pair represents the starting and ending index of a subarray, we need to calculate
the beauty of the array. The process of calculating the beauty involves creating a beautiful
array by processing each pair and appending the subarray defined by the pair to the beautiful
array. After processing all pairs, we need to return the summation of the count of values
exactly lesser than the values at the unused indexes in the original array.
Complete the function calculateBeautyValues in the editor.
calculateBeautyValues has the following parameters:
- 1.
int arr[n]: an array of integers - 2.
int pairs[m][2]: an array of pairs representing subarray indexes
Returns
int: the sum of counts of values less than the values at unused indexes
1Example 1
- Process pair 0-1: beautiful array becomes [1, 2]
- Process pair 3-4: beautiful array becomes [1, 2, 2, 4]
- Process pair 0-0: beautiful array becomes [1, 2, 2, 4, 1]
- Process pair 3-4: beautiful array becomes [1, 2, 2, 4, 1, 2, 4]
Constraints
Limits and guarantees your solution can rely on.
..