HCLTech Interview Question

some programming questions mostly trying to see logic not syntax