TikTok interview question

dynamic programming and other algorithm.