employer cover photo
employer logo
employer logo

Clearwater Analytics (CWAN)

Engaged Employer

Clearwater Analytics (CWAN) Interview Question

Given a binary search tree, write a function that displays the nodes at each level in order.

Interview Answers

Anonymous

Oct 27, 2011

I knew what this question was designed to do (come up with an algorithm that was better than O(n^2)). I didn't know what the best run-time algorithm was, so I just started coding up the O(n^2) algorithm and said that I'll start here and see what can be improved.

Anonymous

Aug 30, 2017

Really two ways to traverse: Depth First Search Breath First Search DFS - can be implemented w/stack (favors going deep off right nodes), preorder (going deep off left nodes and processing parent nodes before children), postorder (going deep off left node and processing children nodes first). BFS - from left to right, level by level, usually implemented with a queue. Which to use is very nuanced. This is a terrible interview question since it's not the algorithm that's important, since the algorithms are already written, but it's the nuance of applying the right search type.