dsa · medium

Min Swaps to Convert BT to BST

GreyOrangeTreeSorting

You may swap any two node **values**. Return the minimum swaps to make the binary tree a BST (shape stays).

Arguments

**Example**

`` Input: [2,[3,None,None],[1,None,None]] Output: 1 ``

Constraints

Number of nodes in [0, 100] Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[2,[3,None,None],[1,None,None]]

Expected:
1

Example 2

Input:
[1,None,None]

Expected:
0

Open in the Dojo editor