Given a non-negative integer N return the number of valley permutations of length N
A valley permutation is defined as a permutation that is a concatenation of two parts: a monotonically decreasing sequence and then a monotonically increasing sequence
Example:
Input: N = 4
Output: 8
Explanation: [
[1, 2, 3, 4],
[2, 1, 3, 4],
[3, 1, 2, 4],
[3, 2, 1, 4],
[4, 1, 2, 3],
[4, 2, 1, 3],
[4, 3, 1, 2],
[4, 3, 2, 1]
]
Notes:
N <= 12
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check