Find the maximum among the count of positive or negative integers in the array | Function to find the maximum of the count of positive or negative elements ; Initialize the pointers ; Find the value of mid ; If element is negative then ignore the left half ; If element is positive then ignore the right half ; Return maximum among the count of positive & negative element ; Driver Code
def findMaximum ( arr , size ) : NEW_LINE INDENT i = 0 NEW_LINE j = size - 1 NEW_LINE while ( i <= j ) : NEW_LINE INDENT mid = i + ( j - i ) // 2 NEW_LINE if ( arr [ mid ] < 0 ) : NEW_LINE INDENT i = mid + 1 NEW_LINE DEDENT elif ( arr [ mid ] > 0 ) : NEW_LINE INDENT j = mid - 1 NEW_LINE DEDENT DEDENT return max ( i , size - i ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ - 9 , - 7 , - 4 , 1 , 5 , 8 , 9 ] NEW_LINE N = len ( arr ) NEW_LINE print ( findMaximum ( arr , N ) ) NEW_LINE DEDENT