Sunday, February 19, 2012

Number streams are same BSTs or Not

You are given 2 number streams. You need to find whether they will create the same BST or not.

Example:
Array1:10 5 20 15 30
Array2:10 20 15 30 5
Result: True

Array1:10 5 20 15 30
Array2:10 15 30 20 5
Result: False[As per diagram below]

                       10                                                                             10
                   /        \                                                                       /          \
                 5         20                                                                   5           15
                          /      \                                                                                  \
                         15     30                                                                               30
                                                                                                                     /
                                                                                                                   20

1 comment:

  1. http://tech-queries.blogspot.in/2011/06/check-if-identical-bsts-from-given.html

    ReplyDelete