Amazon Online Assesment

My friend got this question online assesment , I need your helps guys

Basically the question is
arr of size n is given
Assume arr=[1, 2, 3, 2, 4, 5]
and pairs of size m * 2 is given
{0, 1}, {3, 4}, {0, 0}, {3, 4}
pair represents staring index of the subarray and ending index
We need to calculate beauties of array .
I will show you how it is calculated
Beautiful array []
Process pair 0-1 beautiful array [1,2]
process pair 3-4 beautiful array [1,2,2,4]
process pair 0-0 beautiful array [1,2,2,4,1]
process pair 3-4 beautiful array is [1,2,2,4,1,2,4]
Final Beautiful array is [1,2,2,4,1,2,4]

The Indexes which were unused are index 2, 5
values at index 2 and index 5 are 3 and 5 respectively
we need to return the summation of the count of values exactly lesser than 3 and 5.
In the beautiful array [1,2,2,4,1,2,4] there are 5 values lesser than 3 and 7 values lessed than 5
so count is 5+7 =12
Final Answer is 12

Please help

Comments (6)