title: Given an array of integers. Find the LARGEST subarray with the MAXIMUM sum
body: <p>Hi I am preparing for an interview code test and I stumbled across this question. I tried attempting it in C#, below is my embarrasing answer which I don't even know if it's right but mostly I guess not, could someone please kindly provide me with the answer so that when I rework on the solution I can at least have the answer to verify the output. Thanks.</p>
  
  <p>Sample data:</p>
  
  <pre><code>int[] arr = {5, 1, -7, 3, 7};
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>int[] LargestsubarrayMaxSum(int[] arr)
  {
      int temp = 0;
      int[] resultArr = new int[arr.Length];
  
      for (int i = 0; i &lt; arr.Length - 1; i++)
      {
          if (i != 0)
          {
              foreach (int item in resultArr)
              {
                  temp += item;
              }
  
              if (temp + arr[i + 1] &gt; 0)
              {
                  resultArr[i + 1] = temp + arr[i + 1];
              }
          }
          else
          {
              if ((arr[i] + arr[i + 1]) &gt;= 0)
              {
                  resultArr[i] = arr[i];
                  resultArr[i + 1] = arr[i] + arr[i + 1];
              }
              else
              {
                  resultArr[i] = arr[i];
                  resultArr[i + 1] = 0;
              }
          }
      }
      return resultArr;
  }
  </code></pre>