Codenation hiring test....question 4th

can anyone plzz tell me the approach and provide solution…for this