Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Reorder Array to Get Same BST

med
30 min
Try to solve the Number of Ways to Reorder Array to Get Same BST problem.

Statement

Given an array nums of distinct integers representing a sequence inserted sequentially into an initially empty Binary Search Tree (BST), determine the number of different permutations of nums that will produce the identical BST.

A Binary Search Tree is constructed by inserting the first element as the root, and each subsequent element is recursively inserted into the left subtree if it is strictly smaller than the current node’s value, or into the right subtree if it is strictly greater.

Return the total number of alternative orderings of nums that result in the exact same BST structure and node values. Since the answer can be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤\leq nums.length

  • All integers in nums are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Reorder Array to Get Same BST

med
30 min
Try to solve the Number of Ways to Reorder Array to Get Same BST problem.

Statement

Given an array nums of distinct integers representing a sequence inserted sequentially into an initially empty Binary Search Tree (BST), determine the number of different permutations of nums that will produce the identical BST.

A Binary Search Tree is constructed by inserting the first element as the root, and each subsequent element is recursively inserted into the left subtree if it is strictly smaller than the current node’s value, or into the right subtree if it is strictly greater.

Return the total number of alternative orderings of nums that result in the exact same BST structure and node values. Since the answer can be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤\leq nums.length

  • All integers in nums are distinct.