Infosys Interview Question

Coding question it was tricky