Sorted Permutation Rank Leetcode 150