TikTok interview question

Python code about binary question