TikTok interview question

LC easy solved with binary search