Hello.
I have an alternate solution. No matter whether you have duplicated values or not. It should work for both the scenarios.
You have already sorted your collection in ascending order.
...