KPMG Interview Question

Problem of looping, pattern problems