title: To find the longest substring with equal sum in left and right in C++
body: <p>I was solving a question, with which I am having some problems:</p>
  
  <blockquote>
    <p>Complete the function getEqualSumSubstring, which takes a single argument. The single argument is a string <code>s</code>, which contains only non-zero digits.
    This function should print the length of longest contiguous substring of <code>s</code>, such that the length of the substring is 2*N digits and the sum of the leftmost N digits is equal to the sum of the rightmost N digits. If there is no such string, your function should print 0.</p>
  </blockquote>
  
  <pre><code>int getEqualSumSubstring(string s) {
  int i=0,j=i,foundLength=0;
      for(i=0;i&lt;s.length();i++)
      {
          for(j=i;j&lt;s.length();j++)
          {
              int temp = j-i;
              if(temp%2==0)
              {
                  int leftSum=0,rightSum=0;
                  string tempString=s.substr(i,temp);
                  for(int k=0;k&lt;temp/2;k++)
                  {
                      leftSum=leftSum+tempString[k]-'0';
                      rightSum=rightSum+tempString[k+(temp/2)]-'0';
                  }
                  if((leftSum==rightSum)&amp;&amp;(leftSum!=0))
                      if(s.length()&gt;foundLength)
                      foundLength=s.length(); 
              }
          }
      }
      return(foundLength);
  
  }
  </code></pre>
  
  <p>The problem is that this code is working for some samples and not for the others. Since this is an exam type question I don't have the test cases either.</p>