One-Semicolon Matrix Multiplication
Description:
In this kata, you'll have to write a function multiply(int[][], int[][]) -> int[][]
that multiplies two matrices. The matrices are represented by arrays of rows, where each row is an int[]
. For example, the 3x3 identity represented this way would be:
int[][] ident = new int[][] {
new int[] {1, 0, 0},
new int[] {0, 1, 0},
new int[] {0, 0, 1}
};
Of course, there's a catch: you only get one semicolon!
All the matrices you receive are guaranteed to be valid matrices (i.e. you won't get rows of varying sizes in the same matrix). If a particular multiplication is impossible, your function should return null
. The input arrays will not be empty.
For your convenience, a utility function Utils.print(int[][]) -> void
has been provided. If you pass it a matrix, it'll print it to the console in a somewhat readable fashion. Remember to remove any debug code in your final answer, though -- can't have any stray semicolons!
Good luck!
Similar Kata:
Stats:
Created | Oct 18, 2017 |
Published | Oct 18, 2017 |
Warriors Trained | 490 |
Total Skips | 40 |
Total Code Submissions | 1053 |
Total Times Completed | 92 |
Java Completions | 86 |
C# Completions | 11 |
Total Stars | 17 |
% of votes with a positive feedback rating | 92% of 38 |
Total "Very Satisfied" Votes | 34 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 3 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |