Amazon Interview Question
Software Engineer / Developers[1] Do a pre-order traversal and make an array
[2] for this array (assuming the index starts from 1) for each element at position k the elements at 2k and 2k+1 are its children. hence mark a[k][2k] = 1 and a[k][2k+1] = 1
Maintain a vector of nodes seen so far as we recursively visit the tree. In C++:
- cristi.vlasceanu July 15, 2009