Find the element whose multiplication with | Java program to find minimum index such that sum becomes 0 when the element is multiplied by - 1 ; Function to find minimum index such that sum becomes 0 when the element is multiplied by - 1 ; Find array sum ; Find element with value equal to sum / 2 ; when sum is equal to 2 * element then this is our required element ; Driver code
import java . io . * ; class GFG { static int minIndex ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( 2 * arr [ i ] == sum ) return ( i + 1 ) ; } return - 1 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , - 5 , 3 , 4 } ; int n = arr . length ; System . out . print ( minIndex ( arr , n ) ) ; } }