Given a \(n \times m\) matrix that is sorted on both it’s rows and columns and a value \(x\). Your task is to check if the value \(x\) is contained within the matrix.
Design and implement an algorithm for this problem. Write a function findInSortedTabel(matrix: list, x: int)
, this function receives a 2-dimensional matrix of integers and an integer \(x\) as it’s arguments. The function should return True
if \(x\) is contained within the matrix and False
when the matrix does not contain \(x\).
>>> findInSortedTabel([[0, 2], [2, 4]], 2)
True
>>> findInSortedTabel([[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]], 7)
True
>>> findInSortedTabel([[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]], 4)
True
>>> findInSortedTabel([[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]], 8)
False
>>> findInSortedTabel([], 8)
False