Create two hash sets and store elements both BSTs in them .
HashSet < int > s1 = new HashSet < int > ( ) ; HashSet < int > s2 = new HashSet < int > ( ) ; insertToHash ( root1 , s1 ) ; insertToHash ( root2 , s2 ) ;