title: Algorithm to display emails from different accounts sorted by Date
body: <p>You are probably using such functionality in your day to day if you have an email client on your phone that is connected to your gmail, yahoo, etc and the emails are merged from your accounts ,sorted by date, and displayed in pagination form. </p>
  
  <p>I can only display in 10 increments. i.e First time you see 10 emails, then 20 emails, then 30 and so on ordered by date. Basically just a pagination. </p>
  
  <p>The idea was just to grab 5 emails from each account and order them by date and display 10 of them. The problem happens when I fetch the next set of items. I can still sort this 2 lists again and basically combine them and append to the previously sorted list. However, I started seeing dates from the new fetches that were supposed to be on the first list.</p>
  
  <p>E.g (I'll only put dates of the email since its the important part), </p>
  
  <p>Gmail = <strong>Apr 10,Apr 9,Apr 9,Apr 9,Apr 9,</strong> Apr 9, Apr 9 ,Apr 9 ...</p>
  
  <p>Yahoo= <strong>Apr 10,Apr 9,Apr 8,Apr 7,Apr 6,</strong> Apr 4 ,Apr 4 ,Apr 4.....</p>
  
  <p>Assuming that my gmail and yahoo accounts have each 8 emails (16 total), I need to display the first ten and then the rest 6. </p>
  
  <p>Based on my algorithm (taking 5 from each email account)</p>
  
  <p><strong>First Fetch</strong>=  Apr 10,Apr 10,Apr 9,Apr 9,Apr 9,Apr 9,Apr 9,Apr 8,Apr 
  7,Apr 6</p>
  
  <p><strong>Second Fetch</strong>=Apr 10,Apr 10,Apr 9,Apr 9,Apr 9,Apr 9,Apr 9,Apr 8,Apr 
  7,Apr 6,<strong>Apr 9,Apr 9,Apr 9,Apr 4,Apr 4,Apr 4</strong></p>
  
  <p>As you can see on the second fetch, Apr 9 came after Apr 6 but it was not supposed to be there.</p>
  
  <p>I could have easily merged the second 6 emails with the first fetch by comparing them but the problem when users already started scrolling down, they are not going up to check if the data has been updated or not. So they will lose some of the data.</p>
  
  <p>Assuming that we have to process huge amount of data every minute, how would you solve this scenario with a better performance in <strong>Java 8</strong>? Since storage is an issue, I can't also load all emails from each account in to memory.</p>
  
  <p>I appericiate your help.</p>