Finding local maxima in a 2D array

前端 未结 7 2086
生来不讨喜
生来不讨喜 2021-02-03 12:39

A local maximum in a 2D array can be defined as a value such that all it\'s 4 neighbours are less than or equal to it, ie, for a[i][j] to be a local maximum,

7条回答
  •  余生分开走
    2021-02-03 13:30

    I am pretty sure this cannot be solved in less than O(n^2) comparisons. Assume a chess board 2d matrix where all the white squares are 1 and blacks are 0. It wiil will have O(n^2) solutions and each solution requires at least one comparison.

提交回复
热议问题