TikTok interview question

Tree search and traversing problems , knapsack sometimes too