Here’s a standard way to flatten a 2D array into a 1D array. Suppose A is an 2D array int. I flattens to 1D array F of int. Imagine A as 3 rows of 4 items each. Denote constants R = 3, S = 5. So A(1,2) → F(7). All subscripts are 0-based.
Q2: Now B is 3D array int [Q][R][S], where Q, R and S are the sizes. Implement
You need to work out the algorithm on the white board. I actually drew the 3D array on white board to show my thinking.