Genpact Interview Question

Asked to write a code. Pretty simple.