title: How to optimally divide an array into two subarrays so that sum of elements in both are same, otherwise give an error?
body: <p>How to optimally divide an array into two subarrays so that sum of elements in both subarrays is same, otherwise give an error?</p>
  
  <h3>Example 1</h3>
  
  <p>Given the array</p>
  
  <pre><code>10,  20 , 30 , 5 , 40 , 50 , 40 , 15
  </code></pre>
  
  <p>It can be divided as </p>
  
  <pre><code>10, 20, 30, 5, 40
  </code></pre>
  
  <p>and </p>
  
  <pre><code>50, 40, 15
  </code></pre>
  
  <p>Each subarray sums up to 105.</p>
  
  <h3>Example 2</h3>
  
  <pre><code>10,  20,  30,  5,  40,  50,  40,  10
  </code></pre>
  
  <p>The array cannot be divided into 2 arrays of an equal sum. </p>