Capgemini interview question

Cocubes pattern, pseudo code