Implement stack and tree algorithms | Bytedance Interview Question