Twitch Interview Question

Solve the problem with 5/6 test cases passed.