Split an array into two equal Sum subarrays

`Input : Arr[] = { 1 , 2 , 3 , 4 , 5 , 5  }Output :  { 1 2 3 4 }           { 5 , 5 }Input : Arr[] = { 4, 1, 2, 3 }Output : {4 1}         {2 3}Input : Arr[] = { 4, 3, 2, 1}Output : Not Possible...`
`private static int findSplitPoint(int arr[], int n) {  int leftSum = 0 ;  for (int i = 0; i < n; i++) {    leftSum += arr[i] ;    int rightSum = 0 ;    for (int j = i+1 ; j < n ; j++ )      rightSum += arr[j] ;   if (leftSum == rightSum)     return i+1 ;  }}`
`private static int pointToSplitIntoTwoArrays(int arr[], int n) {   int leftSum = 0;   for (int i = 0 ; i < n ; i++)      leftSum += arr[i];   int rightSum = 0;   for (int i = n-1; i >= 0; i--) {    rightSum += arr[i];    leftSum -= arr[i] ;    if (rightSum == leftSum)       return i ;   }   return -1;}`

--

--

Full Stack Software Developer| Programming enthusiast | Loves DS-Algo and System Design

Love podcasts or audiobooks? Learn on the go with our new app.

Sivareddy Uppathi

Full Stack Software Developer| Programming enthusiast | Loves DS-Algo and System Design