DXC Technology interview question

I was asked to code a complex question