I got the following question in a coding interview for machine learning engineer position.
Write a function:
vector<int> solution(vector<int> &P, vector<int> &Q);
that given a zero-indexed, tensor P which is linearized consisting of M integers and a zero-indexed array Q consisting of N integers representing the size of each dimension of the tensor. It returns an array of integers where each element of the output tensor is the mean of the corresponding element in the input, P, and its neighbor in each dimension. We can treat non-existent neighbors with zero value. Non existent neighbor means neighbor which are outside the tensor dimension. If we wish we can round up the values of the output arrays.
For example:
If P is [1,2,3,4,5,6] and Q is [1,2,3] the P represents the linearization of tensor with an inner-most dimension of 3 and an outer dimension size of 1.
Test case:
[[44,14,92,6],[2,2,1,1]] Expected output: [17,7,16,12]
I was unable to find the solution. If anyone has any idea about the question please share it in the comment box.