简体   繁体   中英

Trench in 2-d array

Suppose there is an nxn array. How to find a pair of indices i and j, such that;

A[i][j] < A[i+1][j], A[i][j] < A[i-1][j], A[i][j] < A[i][j+1],A[i][j] < A[i][j-1]

All I was able to think was an O(n 2 ) algo, which loops across the complete array, and finds the element based on the given conditions.

Can we have a better solution?

Since there is no ordering to the matirx, It is immpossible to confirm existence or non-existence of the index without explicitly checking every index at least once.

By that logic, I am pretty sure this problem should have a lower bound of O(n^2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM