Find the index of the left pointer after possible moves in the array | Function that returns the index of the left pointer ; there 's only one element  in the array ; initially both are at end ; Driver code
< ? php function getIndex ( $ a , $ n ) { if ( $ n == 1 ) return 0 ; $ ptrL = 0 ; $ ptrR = $ n - 1 ; $ sumL = $ a [ 0 ] ; $ sumR = $ a [ $ n - 1 ] ; while ( $ ptrR - $ ptrL > 1 ) { if ( $ sumL < $ sumR ) { $ ptrL ++ ; $ sumL += $ a [ $ ptrL ] ; } else if ( $ sumL > $ sumR ) { $ ptrR -- ; $ sumR += $ a [ $ ptrR ] ; } else { break ; } } return $ ptrL ; } $ a = array ( 2 , 7 , 9 , 8 , 7 ) ; $ n = count ( $ a ) ; echo getIndex ( $ a , $ n ) ; ? >