TikTok interview question

paint the graph using any algo