Hackerrank Contest Question

Hello everyone,
I am stuck with this challenge question. Any ideas?