X DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Kronecker Product
Easy Accuracy: 85.78% Submissions: 559 Points: 2

Given a n*m matrix A and a p*q matrix B, their Kronecker product C = A tensor B, also called their matrix direct product, is an (np)*(mq) matrix.
A tensor B
=
|a11B    a12B|
|a21B    a22B|
=
|a11b11    a11b12    a12b11    a12b12|
|a11b21    a11b22    a12b21    a12b22|
|a11b31    a11b32    a12b31    a12b32|
|a21b11    a21b12    a22b11    a22b12|
|a21b21    a21b22    a22b21    a22b22|
|a21b31    a21b32    a22b31    a22b32|

Example 1:

Input:
n = 2, m = 2
p = 2, q = 2
A = {{1, 2},
{3, 4}}
B = {{0, 5},
{6, 7}}
Output: {{0, 5, 0, 10},
{6, 7, 12, 14},
{0, 15, 0, 20},
{18, 21, 24, 28}}
Explaination: If the multiplication process
is followed then this will be the answer.

You do not need to read input or print anything. Your task is to complete the function kroneckerProduct() which takes n, m, p, q and A and B as input parameters and returns the resultant matrix.

Expected Time Complexity: O(n*m*p*q)
Expected Auxiliary Space: O(n*m*p*q)

Constraints:
1 ≤ n, m, p, q ≤ 20
1 ≤ A[i][j], B[i][j] ≤ 100

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  