Cognizant Interview Question

Coding questions have to be executed then and there with expected output