Triology labs coding round question (Codenation)

There are n gemstones each will give you some amount of bad luck in some seconds. You also have the power to destroy one gemstone in one second while you are recieving bad luck. You cannot destroy gemstone that is giving you bad luck. Only one gemstone can give you bad luck at a time. After a gemstone has gave you its bad luck you can then only move to other gemstone.You can choose gem stone randomly for recieving bad luck and destroy them randomly too.
You are given a 2d array A. The first element (A[i][0]) of each array represent time it takes to give u bad luck and second element([A[I][1]) represent amount of bad luck.
Determine the maximum amount of bad luck that can be avoided.

Input 1
[3,5] -> It takes 3 second for gemstone 1 to give you 5 badluck.(you can chose gems randomly)
[0,8]
[6,5]
[10,3] output -36
[7,4]
[8,6]
[8,8]

input 2

[5,7]
[8,6]
[2,2]
[4,9] output-23
[4,3]

I did sort the elements on the basis of thier badluck and try to destroy gems with most badluck first by while recieving bad luck form gemstone with least bad luck but still was not correct as in input 2 u can recieve badluck from stone 2 which does not have least bad luck but u can avoide 23 badluck as u can destroys all other 4 gemstone as it gives u badluck for 8 seconds.

Comments (7)