Data Structures19 sections · 729 units
Open in Course

Problem - Insert into BST

Add a new value

Given the root of a BST and a value to insert, insert the value into the BST and return the root. It is guaranteed that the new value does not exist in the original BST.

You may return any valid BST after insertion. There can be multiple valid results. Example: Inserting 5 into [4,2,7,1,3][4,2,7,1,3] could produce [4,2,7,1,3,5][4,2,7,1,3,5]. Constraints: up to 10410^4 nodes, values from 00 to 10810^8.