No one has replied
@newtt The inner insert function may move every element in the worst case.
I think the following example could show the problem. Insert numbers as follows:
5, 1, 3, 4
This will create the following tree:
This leaves you with one interval too many, I believe.
I personally think it's neat, but I imagine this method is frowned upon in team environment.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.