Adding two sides of an array
Your code is \$O(n^2)\$. You can improve it to \$O(n)\$ by precomputing a sum array.

int solution(vector&lt;int&gt; &amp;A) {
    int n = A.size();
    int i, j, rsum, lsum, difference;
    int currentmindifference = 1000;

    std::vector&lt;int&gt; pre(n);
    pre[0] = A[0];
    for (i = 1; i &lt; n; i++)
        pre[i] = pre[i - 1] + A[i];

    for(i = 0; i &lt; n; i++)
    {
        lsum = pre[i];
        rsum = pre[A.size() - 1] - lsum;
        difference = abs (lsum - rsum);
        if (difference &lt; currentmindifference) currentmindifference = difference;
    }

    return currentmindifference;
}


Reasoning. By calculating a sum array, we save the need to calculate lsum on each iteration. Furthermore, we notice that we can find rsum by finding the total sum less lsum.

We can simplify this further by noting that lsum and rsum are now superfluous. We will also replace 1000 with std::numeric_limits&lt;int&gt;::max() to ensure we get a true minimum instead of capping it, and check if A is empty before using it.

#include &lt;algorithm&gt;
#include &lt;cmath&gt;
#include &lt;limits&gt;
#include &lt;vector&gt;

int solution(std::vector&lt;int&gt; &amp;A) {
    if (A.empty())
        return -1; // or some other meaningful error value

    int n = A.size();
    int minDifference = std::numeric_limits&lt;int&gt;::max();

    std::vector&lt;int&gt; pre(n);
    pre[0] = A[0];
    for (int i = 1; i &lt; n; i++)
        pre[i] = pre[i - 1] + A[i];

    for (int i = 0; i &lt; n; i++)
        minDifference = std::min(minDifference, std::abs(2 * pre[i] - pre[n - 1]));

    return minDifference;
}


Further reading: Prefix sum array and difference array. Disclosure: I am an administrator on this site. Excuse the formatting.