X interview question

Coding Challenge through hackerrank