title: Check the ordering of 2 different keys in LinkedHashMap in O(1)
body: <p>In a LinkedHashMap, the keys are ordered by when they were inserted into the map.</p>
  <p>For example, consider the following map.</p>
  <pre><code>LinkedHashMap&lt;Integer,Integer&gt; map = new LinkedHashMap&lt;&gt;();
  map.put(1, 1);
  map.put(2, 3);
  map.put(7, 4);
  map.put(5, 6);
  </code></pre>
  <p>So, my understanding of <code>LinkedHashMap</code> is that the keys are stored in the form a Doubly Linked List.</p>
  <p>So, in this example, the keys would be ordered as <code>1&lt;-&gt;2&lt;-&gt;7&lt;-&gt;5</code></p>
  <p>Now, my requirement is this. Given 2 keys from this map, is it possible to check which one came first or last?</p>
  <p>For example, a function like the following</p>
  <pre><code>public boolean isFirst(int key1,int key2){
  // logic to compute if key1 is first
  }
  </code></pre>
  <p>Now, the above function can be done in O(n) easily by maintaining another map to get the order and compare it.</p>
  <p>I want to do this operation in O(1). If it is possible, then should I maintain some other data structure to handle insertion, removal and updation of keys in the map ?</p>