Pergunta de entrevista da empresa Bloomberg

Binary search tree, find the second largest element.

Resposta da entrevista

Sigiloso

17 de ago. de 2023

First the brute force- in-order traversal, store all elements which will be in ascending order. 2nd last element will be the desired output. Secondly to not traverse the entire tree but make a decision at each node and decide which side to go as its a BST. But I got stuck for one case out of the 4 possible. However the optimized solution is very easy. In-order traversal but instead of left-root-right, traverse right-root-left.