I've been doing some exercises from codingbat, and I haven't figure out a way to solve this particular problem; may be someone could point me how to approach this. Thanks

Jorge Vazquez wrote:I've been doing some exercises from codingbat, and I haven't figure out a way to solve this particular problem; may be someone could point me how to approach this. Thanks

It's divided into n sections. Inside each section is n numbers (n*n). Each section is essentially counting down. With each section progression the number of zeros decreases by 1 and the appropriate number for the count down is inserted. If that get you thinking about it the right way, I'll show you some example code that might help.

Well, this is an outline of my first thoughts of how to solve it.

Firstly, break the array up into n groups. So that means we've got an outer loop from 1 to n.

Then I'd fill each group from the right-hand side. That means you're counting up from 1 to the group index to work out the value you're inserting, so you've got an inner loop. Then it's just a matter of working out the array position based on the two loop indices.