W.C 3.3 Breaking Labs

Walter White is experimenting with a set of chemicals, each having a specific integer molecular weight.
In every turn, he selects any 2 chemicals from the set and mixes them together. Suppose he mixes two
chemicals with molecular weights A and B together, such that A <= B.

1 If A == B both the chemicals explode, there is no residue left and both the chemicals are
removed from the array.
2 If A != B, the chemical of molecular weight A is totally destroyed, and the chemical of
molecular weight B has new molecular weight, B – A.

At the end, there is at most 1 chemical left. Return the smallest possible molecular weight of this
chemical (the weight is 0 if there are no chemicals left)


Input: [2, 7, 4, 1, 8, 1]

Output: 1


Combine 2 and 4 so the output array turns into [7,2,1,8,1], then combine 7 and 8 so the array converts
into [2,1,1,1], then combine 2 and 1 so that the array turns converts into [1,1,1], then combine 1 and 1
so that the array turns into [1], leading to the optimal value.
testcases = link

Final ans should be sum of all 5 testcases.

This challenge is worth 100 points.

You must be logged in to submit a solution

View ranklist for this challenge
About scoring and submission

Contact Us

Kunal Desai : 7715051136

Neelraj Patil : 9930671144

Privacy Policy