L&T Technology Services Interview Question

Python coding question to solve