Practice Number of Ways to Reorder Array to Get Same BST
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Hard#1569
LeetCode ProblemNumber of Ways to Reorder Array to Get Same BST
Problem Statement
Insert the permutation nums of integers 1 through n, in order, into an initially empty binary search tree. Count other permutations that produce exactly the same tree, excluding the original ordering itself. Return the count modulo 10^9 + 7.
Source: Number of Ways to Reorder Array to Get Same BST on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [2,1,3]
Output
1
# Example 2
Input
nums = [3,4,5,1,2]
Output
5
# Example 3
Input
nums = [1,2,3]
Output
0
Constraints
1 <= nums.length <= 1000
1 <= nums[i] <= nums.length
All integers in nums are distinct.
Related LeetCode Problems
Practice more problems similar to Number of Ways to Reorder Array to Get Same BST.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.