HEIGHTS-Editorial

you have to handle the edge case. The edge case being:
[1 1 2] => [2 2 2]
[1 1 2 2 3] => [1 1 3 3 3]
[1 1 2 2 3 3 4] => [1 1 2 2 4 4 4]

Meaning you have a list with the following properties:
1st: biggest element exists exactly once
2nd: all other elements exist EXACTLY twice

A way to do this is to add all elements to a map. Then ensure that the biggest element exists once and all other elements exactly twice. If that is the case, you print 2.

If this is not the case, you continue doing what you did before. Everything works, just not the edge case.

2 Likes