TikTok interview question

Given example data, use SQL to get output in this format.