Sparse Matrix Multiplication in COO Form
Updated
Problem statement
Matrix A has shape rowsA x shared and matrix B has shape shared x colsB. Each operand is given in coordinate-list (COO) form: every row [r,c,value] stores one nonzero integer at that zero-based coordinate. Coordinates are unique within each operand; missing cells equal zero.
Return the ordinary matrix product A times B in the same COO form. Omit zero output cells, including cells whose nonzero contributions cancel. Sort the output rows by coordinate, first row then column. Inputs need not be sorted.
Function
multiplySparseCOO(rowsA: int, shared: int, colsB: int, a: int[][], b: int[][]) → int[][]Examples
Example 1
rowsA = 2shared = 3colsB = 2a = [[0,0,2],[0,2,3],[1,1,-1]]b = [[0,1,4],[2,0,5],[1,1,6]]return = [[0,0,15],[0,1,8],[1,1,-6]]Three matching inner coordinates contribute to three nonzero output cells.
Example 2
rowsA = 2shared = 3colsB = 2a = [[0,0,5]]b = [[1,1,7]]return = []No A column matches a B row, so the product is all zero.
Example 3
rowsA = 1shared = 2colsB = 1a = [[0,0,1],[0,1,1]]b = [[0,0,3],[1,0,-3]]return = []Two contributions cancel, and COO omits the zero result.
Constraints
1 <= rowsA, shared, colsB <= 50.0 <= a.length, b.length <= 200.- Each COO row has three integers with an in-range row and column, a nonzero value in
[-100, 100], and no duplicate coordinate in the same operand. - Every output value fits in a signed 32-bit integer.
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
- Sparse Matrix Addition and MultiplicationPinterest · PHONE SCREENPinterest interview questions
- Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Sparse Matrix MultiplicationByteDance · PHONE SCREENByteDance interview questions
- Valid SudokuVerkada · PHONE SCREENVerkada interview questions
- Configurable Tic-Tac-Toe GameEliseAI · PHONE SCREEN
- Validate Completed SudokuApple · PHONE SCREENApple interview questions
- Game of Life on a Finite and an Infinite BoardCitadel · PHONE SCREENCitadel interview questions
- Layered Rectangle CanvasRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
Meta interview experiences
- Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
- Meta Business Support Engineer Phone Screen: 1 Experience
- Meta Software Engineer Onsite Questions: 3 Experiences
- Meta AI Native Engineer OA and Onsite: 1 Experience
- Meta AI-Native Coding Interview: 3 Experiences
- Meta Production Engineer Intern Questions: 6 Experiences