Given a matrix of order n*n. I need to find the length of the largest sorted sub-matrix (sorted both in row-wise and column-wise manner in increasing order).
I made the following code which is not giving out the correct output because of some error in my logic.
My pseudo code:
arr=[map(int,raw_input().split()) for j in range(n)] #given list
a=[[0 for j in range(n)]for i in range(n)] #empty list
a[0][0]=1
for i in range(n):
for j in range(1,n):
if i==0 and arr[i][j-1]<=arr[i][j]: #compare list element with the
right element
a[i][j-1]=a[i][j-1]+1
if i>0 and arr[i][j-1]>=arr[i-1][j-1]: #compare list element with the
top for i>0
a[i][j-1]=a[i-1][j-1]+1
if i>0 and arr[i][j-1]<=arr[i][j]: #compare the same element with the
right element for i>0
a[i][j-1]=a[i][j-1]+1
print maximum number present in a
Given array:
2 5 3 8 3
1 4 6 8 4
3 6 7 9 5
1 3 6 4 2
2 6 4 3 1
expected output=8 (length of maximum sorted sub-matrix)
1 4 6 8
3 6 7 9
is the sub-matrix which is sorted both row-wise and column-wise
What should be my approach?