<p>A <strong>peak</strong> element in a 2D grid is an element that is <strong>strictly greater</strong> than all of its <strong>adjacent </strong>neighbors to the left, right, top, and bottom.</p>

<p>Given a <strong>0-indexed</strong> <code>m x n</code> matrix <code>mat</code> where <strong>no two adjacent cells are equal</strong>, find <strong>any</strong> peak element <code>mat[i][j]</code> and return <em>the length 2 array </em><code>[i,j]</code>.</p>

<p>You may assume that the entire matrix is surrounded by an <strong>outer perimeter</strong> with the value <code>-1</code> in each cell.</p>

<p>You must write an algorithm that runs in <code>O(m log(n))</code> or <code>O(n log(m))</code> time.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2021/06/08/1.png" style="width: 206px; height: 209px;" /></p>

<pre>
<strong>Input:</strong> mat = [[1,4],[3,2]]
<strong>Output:</strong> [0,1]
<strong>Explanation:</strong>&nbsp;Both 3 and 4 are peak elements so [1,0] and [0,1] are both acceptable answers.
</pre>

<p><strong class="example">Example 2:</strong></p>

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2021/06/07/3.png" style="width: 254px; height: 257px;" /></strong></p>

<pre>
<strong>Input:</strong> mat = [[10,20,15],[21,30,14],[7,16,32]]
<strong>Output:</strong> [1,1]
<strong>Explanation:</strong>&nbsp;Both 30 and 32 are peak elements so [1,1] and [2,2] are both acceptable answers.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>m == mat.length</code></li>
	<li><code>n == mat[i].length</code></li>
	<li><code>1 &lt;= m, n &lt;= 500</code></li>
	<li><code>1 &lt;= mat[i][j] &lt;= 10<sup>5</sup></code></li>
	<li>No two adjacent cells are equal.</li>
</ul>

"""
Here, we will solve the problem using the binary search approach and return the max local element 

steps:
1. define the low and the high element 

"""

class Solution:
    def findPeakGrid(self, mat: List[List[int]]) -> List[int]:

        def find_highestRow(mat, m , n , col ):
            max_value = -1
            index = -1
            for i in range(m):
                if (mat[i][col] > max_value):
                    max_value = mat[i][col]
                    index = i

            return index


        #define the m and n 
        m = len(mat) # i down => rows
        n = len(mat[0]) # j right => columns
        print( m , n)

        #high and low
        low = 0
        high = n - 1  
        #We are gonna look at each individual column
        print(low , high)

        while (low <= high):
            #now find the mid element
            mid = (low + high) // 2
            #now we need to find the row so that we can take the decision to go left or right
            print(mid)

            #finding the highest row
            maxRowIndex = find_highestRow(mat, m , n , mid)
            print("maxRowIndex", maxRowIndex)

            #now we are having the highest row which we can find it using the binary search
            #now we need to just find the left and right comparision as the element is highest in the column
            left_ele = -1
            right_ele = -1
            if (mid - 1  >= 0):
                left_ele = mat[maxRowIndex][mid - 1]
            if (mid + 1  < n):
                right_ele = mat[maxRowIndex][mid + 1]

            current_ele = mat[maxRowIndex][mid]
            print("left_ele ", left_ele, " right_ele ", right_ele, " current_ele", current_ele )
            #now we can compare them 
            if (current_ele > left_ele) and (current_ele > right_ele):
                return [maxRowIndex, mid]
            elif (current_ele < left_ele):
                #now the element is one the left side 
                high = mid - 1
            else:
                low = mid + 1

        return [-1, -1]

        
851