Capgemini Interview Question

Cocubes pattern, pseudo code