3 kyu
T.T.T.35: Complete a matrix(3x3)
139myjinxin2015
Description:
Description
Here is a matrix(3x3), each element is a positive integer. We don't know all of their values, but we know the sum of each row and each column are equal. This matrix is not complete, please fill in all the numbers.
Task
Complete function completeMatrix()
that accepts a argument matrix
. This matrix has some null values. Please fill in the correct number and return it.
If the matrix is not possible to complete (the condition is not enough or the value is wrong), please return null
.
Examples
matrix=[
[ 10 ,null, 3 ],
[ 4 ,null, 16 ],
[null, 12 ,null]
]
completeMatrix(matrix) should return:
[
[10, 8, 3],
[ 4, 1,16],
[ 7,12, 2]
]
because: 10+8+3=21,4+1+16=21,7+12+2=21 //rows
10+4+7=21,8+1+12=21,3+16+2=21 //columns
matrix=[
[ 10 ,null, 8 ],
[ null,11, 6 ],
[null, 7 ,null]
]
completeMatrix(matrix) should return null
because the condition is not enough
matrix=[
[ 10 ,null, 8 ],
[null,null, 6 ],
[ 8 , 7 ,null]
]
completeMatrix(matrix) should return null
because the value is wrong,
8+6+num and 8+7+num is not possible equal
matrix=[
[null,17,4],
[null,3,null],
[null,1,18]
]
completeMatrix(matrix) should return null
because the value is wrong,
the possible result contains negative number
Matrix
Algorithms
Similar Kata:
Stats:
Created | Aug 15, 2016 |
Published | Aug 15, 2016 |
Warriors Trained | 1173 |
Total Skips | 310 |
Total Code Submissions | 2696 |
Total Times Completed | 139 |
JavaScript Completions | 139 |
Total Stars | 58 |
% of votes with a positive feedback rating | 95% of 44 |
Total "Very Satisfied" Votes | 41 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 4 |
Average Assessed Rank | 2 kyu |
Highest Assessed Rank | 2 kyu |
Lowest Assessed Rank | 3 kyu |