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 (see corresponding trees below)
1st Approach (Basic Solution)
Algorithm.
1.Create BST from each Array O(nlogn)
2.Check two BST are same or not by comparing each nodes both at poistion.
Time Complexity O(nlogn)
Space Complexity O(1)
2nd Approach
2 comments :
wot is the 2nd approach?
bhai 2nd approch to bata de yaar
Post a Comment