DXC Technology Interview Question

I was asked to code a complex question