Publicis Sapient interview question

Some coding round i got stuck .. almost based on strings