Meta Interview Question

1. "Write a code telling wether a string is a valid number". Some basic examples are given, but you can dig in by giving your own examples of complex bad and good cases, like: "- .5" or "001", etc. Mostly depends on your fantasy 2. "Given a binary tree with unique values in nodes, for a query of two different nodes find the lowest common ancestor in this tree". Given the tree == given the root. A tree is a DAG, so no back edges from children to parent presented (but you are supposed to think of it and ask things like that, I presume)

Interview Answer

Anonymous

Apr 8, 2022

1. Simple "for" cycle with a set of boolean variables and a logic written in if-else blocks. Almost all the logic is pointed at finding a bad symbol and returning False immediately. Time: O(n). Additional space: O(1) 2. Depth-First Search + boolean variables indicating wether each query node was met. Once each of children calls returned True, return the node you're currently in and break. Time: O(n*log(n) ). Additional space: O(1)