Matrix-Flatten

Problem

1. Problem Description

A 3D matrix is to be stored in a 1D vector (flattened). The 3D matrix is of size n x m x p and is indexed by i, j, k. The 1D vector is of size q and is indexed by y.

2. Requirements

Implement the following functions:

  1. Create a 1D vector suitable for storing the 3D matrix.
  2. Convert the 3D matrix index (i, j, k) to a suitable 1D vector index (y). Must be O(1).

The following is irrelevant:

1. The exact way the matrix is converted into the array.

picture alt

2. The complexity of the solution.

O(n*m*p)

3. The programming language.

C++