Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
3,062 views

For proper oa or interview experiences list of all top tech companies visit :

https://oa.desiqna.in

https://interview.desiqna.in

 

image

 

in Online Assessments by Expert (44,360 points) | 3,062 views

1 Answer

0 like 0 dislike
There are two integer arrays, singer[n] and length[n]. Each song is described as singer[i] and length[i]. The fun amount for a song is the product of its length and the total number of different singers heard in all prior songs plus the singer of the current song. The songs can be played in any order.


Arrange the songs to produce the maximum possible fun listening to the entire playlist. Return that maximum fun value.


Constraints
1 \le≤ n \le≤ 10 5
1 \le≤ singer[i] \le≤ 10 9
1 \le≤ length[i] \le≤ 10 9



Example - 1


Given n = 3, singer[i] = [1, 2, 2] and length[i] = [2, 3, 2], the optimal order is

the first song, 1*2 = 2.
the third song, 2 * 2 = 4.
the second song, 2 * 3 = 6.
The maximum fun possible is 2 + 4 +6 = 12.



Example - 2


Given n = 3, singer[i] = [1, 1, 2] and length[i] = [5, 4, 3]
It is optimal to listen to the second song, the third song, and finally, the first song (1 * 3) + (2 * 4) + (2 * 5) = 21



Return the maximum value of fun value.


 

by Expert (44,360 points)
0 0
I am unable to find answer please guide me to find