Publicis Sapient Interview Question

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