Since A is m×n and AB defined therefore B should be n×p because the number of columns of A should be equal to number of rows of B.
Again B is row n×p and A is m×n.
And since BA is also defined therefore p should be equal to m by the same argument as above i.e., p = m
∴ B is n×m matrix.