# Find smallest particle by removing them and add by their absolute difference

You have given n particles (> 0). You smash them two particles and genrates new particle by their absolute difference. Old particles have vanished.

If particles can be samshed any way Print minimum particle can be got.

Constraint: 1 <= particle <= 10^4

Eg1:
I/p: 30 27 26 10 6
O/p: 0

Explanation:
30 26 samshes gives 4. Updated array 4 27 10 6
10 6 samshes gives 4. Updated array 4 27 4
4 4 samshes gives 0. Updated array 27 0
Min particle is 0

Eg2:
I/p: 1 2 4 8
O/p: 1

Explanation:
No matter how you smash min particle is 1

Eg3:
I/p: 101 75 40 30
O/p: 4

Explanation:
101, 75 --> 26 then 30, 26 --> 4.

Please provide the link of the problem.

It was asked in company. If you have difficulty to understand please point out. I try to clear things

Generally people avoid such request in which the problem link is not provided. It may be possible that, It was asked from a on-going contest. which not fair, So try to put linkâ€™s for fast and better reachâ€¦your explanation is clear cut.

1 Like

I think it can be done using multisetâ€¦ you have to insert every element into a multisetâ€¦ then from the end you should pick two elements smash them erase both elements and then insert the absolute difference into the multiset againâ€¦ in the end remaining element is the answerâ€¦ if none remains then answer is zeroâ€¦

@abdullahmoosa your solution wonâ€™t work.