Solve stock profit and vertical tree traversal | Uber Interview Question