Changed the solution to simply remove the duplicates since that situation cannot happen any other way