HackerEarth Interview Question

it's on the leetcode discussion you can find it