Construct the Lexicographically Largest Valid Sequence - Leetcode 1718 - Python