HCLTech interview question

WAP for GCD