# 311 Sparse Matrix Multiplication

Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is equal to B's row number. Example:

```
        A = [
          [ 1, 0, 0],
          [-1, 0, 3]
        ]

        B = [
          [ 7, 0, 0 ],
          [ 0, 0, 0 ],
          [ 0, 0, 1 ]
        ]


             |  1 0 0 |   | 7 0 0 |   |  7 0 0 |
        AB = | -1 0 3 | x | 0 0 0 | = | -7 0 3 |
                          | 0 0 1 |
```

```cpp
// not the correct solution, but I am skipping this problem for now.

  vector<int> multiply(vector<vector<int>> *A, vector<vector<int>> *B)
  {
      vector<int> result;
      int sum = 0;
      // mulitply every row
      for (int i = 0; i < A[0].size(); ++i) {
          // with every column
          for (int j = 0; j < (*B).size(); ++j) {
              sum += (*A)[i][j] * (*B)[j][i];
          }
          result.push_back(sum);
          sum = 0;
      }


      return result;
  }


  int main()
  {
      vector<vector<int>> arrayA = {    { 1, 0, 0 }, 
                                      { -1, 0, 3 } 
                                   };


      vector<vector<int>> arrayB = { 
                                      { 7, 0, 0 },
                                      { 0, 0, 0 }, 
                                      { 0, 0, 1 } 
                                   };
  }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/311_sparse_matrix_multiplication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
