Implement stack variants and upward path sum | Bytedance Interview Question