3 kyu

T.T.T.35: Complete a matrix(3x3)

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

Stats:

CreatedAug 15, 2016
PublishedAug 15, 2016
Warriors Trained1173
Total Skips310
Total Code Submissions2696
Total Times Completed139
JavaScript Completions139
Total Stars58
% of votes with a positive feedback rating95% of 44
Total "Very Satisfied" Votes41
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments4
Average Assessed Rank
2 kyu
Highest Assessed Rank
2 kyu
Lowest Assessed Rank
3 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • kontic Avatar
Ad