← 返回 linkedin 的题目列表Sparse Vector and Matrix Multiplication
类型:online_judge
Design a class for sparse vector and sparse matrix multiplication. The class should support the design of constructor, functions, attributes, and variables. Implement the sparse characteristics so that time complexity is not O(M*N), and optimize memory usage. Provide test cases.
Input Format:
The sparse matrix is given as a list where each element is a triplet (i, j, value) indicating an element in the matrix at row i and column j.
The sparse vector is given as a list where each element is a pair (j, value) indicating the element in the vector at position j.
Output Format:
The output is a list containing the resulting values of the vector product.
Example:
Input:
Sparse Matrix: [(0, 1, 3), (1, 1, 4), (1, 2, 5)]
Sparse Vector: [(1, 2), (2, 3)]
Output:
[6, 23]
Example
Input
3
1
3
(0, 1, 3) (1, 1, 4) (1, 2, 5)
1
(1, 2) (2, 3)