Find the maximum among the count of positive or negative integers in the array | Java program for the above approach ; 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
import java . io . * ; public class GFG { static int findMaximum ( int arr [ ] , int size ) { int i = 0 , j = size - 1 , mid ; while ( i <= j ) { mid = i + ( j - i ) / 2 ; if ( arr [ mid ] < 0 ) i = mid + 1 ; else if ( arr [ mid ] > 0 ) j = mid - 1 ; } return Math . max ( i , size - i ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 9 , - 7 , - 4 , 1 , 5 , 8 , 9 } ; int N = arr . length ; System . out . println ( findMaximum ( arr , N ) ) ; } }