KPMG interview question

Problem of looping, pattern problems