Maximum Element After Decreasing and Rearranging - Leetcode 1846 - Python