Multiply Two Matrices
Updated
Problem statement
You are given two integer matrices: a with m rows and n columns, and b with n rows and p columns. Return their product c = a * b, a matrix with m rows and p columns.
Entry c[i][j] is the sum of a[i][t] * b[t][j] over every t from 0 to n - 1: row i of a combined with column j of b. The entries can be larger than a 32-bit integer can hold.
Function
multiplyMatrices(a: int[][], b: int[][]) → long[][]Examples
Example 1
a = [[2,0,-1],[1,3,2]]b = [[1,4],[0,-2],[5,1]]return = [[-3,7],[11,0]]a is 2 x 3 and b is 3 x 2, so the result is 2 x 2. Row 0 of a times column 0 of b: 2*1 + 0*0 + (-1)*5 = -3. Row 0 times column 1: 2*4 + 0*(-2) + (-1)*1 = 7. Row 1 times column 0: 1*1 + 3*0 + 2*5 = 11. Row 1 times column 1: 1*4 + 3*(-2) + 2*1 = 0.
Example 2
a = [[3]]b = [[1,-2,5]]return = [[3,-6,15]]A 1 x 1 matrix times a 1 x 3 matrix: each entry of b's only row is multiplied by 3.
Example 3
a = [[1],[2]]b = [[4,5]]return = [[4,5],[8,10]]A 2 x 1 matrix times a 1 x 2 matrix gives a 2 x 2 result: entry [i][j] is a[i][0] * b[0][j], so the rows are 4, 5 and 8, 10.
Constraints
ahasmrows andncolumns;bhasnrows andpcolumns1 <= m, p <= 40and1 <= n <= 100-10^4 <= a[i][j], b[i][j] <= 10^4
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- One-Nearest-Neighbor Classification with Manhattan DistanceOpenAI · PHONE SCREENOpenAI interview questions
- Matrix Multiplication With and Without NumPyNVIDIA · PHONE SCREENNVIDIA interview questions
- Adjacent Order-Statistic Gap DistributionsScale AI · PHONE SCREENScale AI interview questions
- Scaled Dot-Product AttentionAmazon · PHONE SCREEN
- Rotate ImageTokopedia · PHONE SCREENTokopedia interview questions
- Rotate ImageSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
- Survey Table: Group Given an AnswerSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- Linear Layer Forward and Backward PassesMeta · ONSITE INTERVIEWMeta interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
- Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)