title: how to find latest element added or deleted in dynamic array
body: <p>I am getting an input array in loop which contains numbers in sorted order. on Every iteration the input array will either be added or be deleted with any one number (no duplicates in input array). Example</p>
  
  <pre><code>1st iteration: Input Array [3,4,8,19]
  2nd iteration: Input Array [3,4,5,8,19]
  Output: 5 added
  3rd iteration: Input Array [3,4,5,8,19,40]
  Output: 40 added
  4th iteration: Input Array [3,5,8,19,40]
  Output: 4 deleted
  5th iteration: Input Array [1,3,5,8,19,40]
  Output: 1 added
  </code></pre>
  
  <p><strong>Note:</strong> I have a solution where I can take a map or different array and copy the input array in new array then from next iteration onward I'm going to iterate input array and compare the input array's elements with new array, the one not present in new array is the one added; and the one present in new array but not present in input array is the one deleted. I am looking for a better approach with most optimized logic in terms of space and time.</p>