79116291

Date: 2024-10-23 05:21:32
Score: 5.5
Natty:
Report link

Sorry, since I don't yet have 50 reputation, I can't comment on the best answer (@maxim1000's algorithm), so I'm using the answer section to raise my question.

After trying this algorithm on an example array I came up with, it seems like the algorithm fails to correctly identify the peak in this case.

Consider the following 5x5 array:

    0   1   2   3   4
    ------------------
0 |  9   19  20  31  64
1 |  49  72  71  51  44
2 |  5   141 95  6   7
3 |  35  36  27  28  50
4 |  10  88  29  189 21

First iteration: The algorithm selects column 2 as the middle column and finds the maximum in columns 1, 2, and 3. The maximum is 189 in column 3. As a result, the algorithm proceeds to the right_side + central_column of this subarray, creating a 5x3 subarray and recursively applies the algorithm on it.

    0   1   2
    -----------
0 |  20  31  64
1 |  71  51  44
2 |  95   6   7
3 |  27  28  50
4 |  29  189 21

Second iteration: The algorithm now selects row 2 as the middle row and finds the maximum in rows 1, 2, and 3. The maximum is 95 in row 2. Since the maximum is in the middle row, the algorithm incorrectly considers 95 as the peak, even though it is not the actual peak in the array.

Thanks in advance for any clarification or suggestions!

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • RegEx Blacklisted phrase (1): can't comment
  • RegEx Blacklisted phrase (3): Thanks in advance
  • RegEx Blacklisted phrase (1.5): 50 reputation
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Jacky