Given a Matrix, extract rows with AP sequence.
Input : test_list = [[4, 7, 10], [8, 10, 12], [10, 11, 13], [6, 8, 10]]
Output : [[4, 7, 10], [8, 10, 12], [6, 8, 10]]
Explanation : 3, 4, and 2 are common difference in AP.
Input : test_list = [[4, 7, 10], [8, 10, 13], [10, 11, 13], [6, 8, 10]]
Output : [[4, 7, 10], [6, 8, 10]]
Explanation : 3 and 2 are common difference in AP.
In this, we check for all the elements having a common difference using a loop, if any element not found to be in sync, then the row is flagged off and not added to the result.
The original list is : [[4, 7, 10], [8, 10, 12], [10, 11, 13], [6, 8, 10]]
Filtered Matrix : [[4, 7, 10], [8, 10, 12], [6, 8, 10]]
In this, we check for all values to have common difference using all(), list comprehension is used to perform an iteration of rows.
The original list is : [[4, 7, 10], [8, 10, 12], [10, 11, 13], [6, 8, 10]]
Filtered Matrix : [[4, 7, 10], [8, 10, 12], [6, 8, 10]]
The time complexity of this code is O(nm), where n is the number of rows and m is the number of columns in the input matrix.
The auxiliary space complexity of this code is O(nm), which includes the space required for the numpy array arr, the intermediate array diffs, the boolean mask mask, and the resulting filtered list res.