A few observations were required to solve this problem.
If these conditions hold, a tree can always be built conforming to the given ranges. We can check if these conditions hold using stacks in O(N) time.
Judge solution: Link
Complexity: O(N)
Alternate: Tarango Khan