Round 1
Questions:
Design a data structure that could represent the above tree.
A string can be broken into multiple strings and represented as a binary tree where each external node contains a string and a data field and each internal node in the tree contains a numerical value that is the sum of the data fields of its left and right child nodes. For example, if the left child has a data field of 5 and the right child has a data field of 7, the internal node would contain the sum of these values, 12.
Example:
So, here the complete string would be APPLEPIEBANANA.
Follow-up Question
Find the Nth character in the string.
Candidate's Approach
Created a Node class, and two classes InternalNode and ExternalNode would inherit from it. For the follow-up question, implemented a recursive function with a count variable to traverse the tree, allowing navigation to either the left or right child. This approach solves the problem in O(height of tree).
Interviewer's Feedback
Interviewer seemed happy with the approach taken.