Mubashir needs your help to find out a wrong number in a 2D array.
Imagine a 2D array of numbers given below:
var arr = [
[1, 2, 3, 6 ],
[4, 5, 6, 15],
[7, 8, 9, 24],
[12,15,18,45]
]
You can notice that:
See below examples for a better understanding:
arr1 = [
[2, 2, 3, 6 ],
[4, 5, 6, 15],
[7, 8, 9, 24],
[12,15,18,45]
]
// 2 is incorrect in the first row and first column.
// Replace it with 1.
arr2 = [
[1, 2, 3, 7 ],
[4, 5, 6, 15],
[7, 8, 9, 24],
[12,15,18,45]
]
// 7 is incorrect in the first row and fourth column.
// Replace it with 6.
arr3 = [
[1, 2, 3, 6 ],
[4, 5, 6, 15],
[7, 8, 9, 24],
[12,15,18,46]
]
// 46 is incorrect in the fourth row and fourth column.
// Replace it with 45.
wrongNumber(arr1) ➞ 1
wrongNumber(arr2) ➞ 6
wrongNumber(arr3) ➞ 45
N/A