How to 3D Array to 1D Array -> index conversion?

I need a conversion of 3D<->1D index of an array[x][y][z] into array2[i].

I checked this thread at stackoverflow:

and grabbed their solution for

i = x + y*xMax + z*yMax*xMax

But i stumbled uppon the following problem:
Let’s assume i have a 3D “Wall” of the dimensions 1x3x3, which makes :

xMax = 1
yMax = 3
zMax = 3

Now storing those two elements at: [1][0][0] ; [0][1][0] inside array2[i] would result in:

[1][0][0] : i = 1 + 0*1 + 0*3*1 = 1
[0][1][0]: i = 0 + 1*1 + 0*3*1 = 1

Both elements interfere at the same index, what am i doing wrong or missing out?

you shouldn’t call the variables xMax, yMax, and zMax, because they are not actually the maximum index number, but the number of indices.
If you have an array A[4] it has indices of 0, 1, 2, and 3. the ‘max x’ is 3
your 3d array of 1x3x3 is essentially a 2d array, since one of the dimensions is 1.The first point actually doesn’t exist in your wall.