Its not that hard.
because when (j=0;j<=60;j+=15)
then you get j=0,15,30,45,60
when (j=1)
you get j=1,16,31,46
Look when you said j=0, then the loop will run (5 times for j)*(4 times for i) so total 20 times; however, interval can have 17 elements. so when it gets interval[18] gives you error.
Then when you use j=1. The loop would run (4 times for j)*(4 times for i)
so total 16 which is valid for interval, and it works.