TapeEquilibrium


Here my solution in C++

#include <vector>
#include <numeric>

using namespace std;

int solution(vector<int> &A)
{
   const size_t size = A.size();

   int diff = 0;
   int min_diff = -1;

   int suml = 0;
   int sumr = std::accumulate(A.begin(), A.end(), 0);

   for ( size_t p = 1; p < size; ++p )
   {
      suml += A[p-1];
      sumr -= A[p-1];

      diff = suml > sumr ? suml - sumr : sumr - suml;

      if ( min_diff<0 || diff < min_diff )
         min_diff = diff;
   }

   return min_diff;
}
Comments