HCLTech interview question

some programming questions mostly trying to see logic not syntax