← Back to challenges

Wrong Number

PythonHardalgorithmsmathnumbersloops

Instructions

Mubashir needs your help to find out a wrong number in a 2D list.

Imagine a 2D list of numbers given below:

lst = [
  [1, 2, 3, 6 ],
  [4, 5, 6, 15],
  [7, 8, 9, 24],
  [12,15,18,45]
]

You can notice that:

  • The end number of each row is the sum of each row's previous numbers.
  • The end number of each column is the sum of each column's previous numbers.

See below examples for a better understanding:

lst1 = [
  [2, 2, 3, 6 ],
  [4, 5, 6, 15],
  [7, 8, 9, 24],
  [12,15,18,45]
]

# 2 is incorrect in first row and first column.
# Replace it with 1.

lst2 = [
  [1, 2, 3, 7 ],
  [4, 5, 6, 15],
  [7, 8, 9, 24],
  [12,15,18,45]
]

# 7 is incorrect in first row and fourth column.
# Replace it with 6.

lst3 = [
  [1, 2, 3, 6 ],
  [4, 5, 6, 15],
  [7, 8, 9, 24],
  [12,15,18,46]
]

# 46 is incorrect in fourth row and fourth column.
# Replace it with 45.

Examples

wrong_number(arr1) ➞ 1

wrong_number(arr2) ➞ 6

wrong_number(arr3) ➞ 45

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.