Solve tree diameter and grid path problems | Meta Interview Question