Problem statement

https://binarysearch.com/problems/Lexicographically-Largest-Mountain-List/

Solution

Not difficult problem, but with several edge cases, need to be careful. The quesion is what is the biggest number we can start with.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, n, l, u):
        t = min(n - 2, u - l)
        x = u - (n - t) + 1
        if x < l: return []
        return list(range(x, u + 1)) + list(range(u - 1, u - t - 1, -1))