title: Repeated element at top of the stack on basis of their second appearance
body: <p>I have an array which consist of duplicate elements e.g.</p>
  <pre><code>arr = [1, 2, 3, 0, 2, 1]
  </code></pre>
  <p>Now, I want to store elements in a stack in such a way that top of the stack will always give me an element which is repeated and it appear before all other repeated element which comes afterwards.
  for e.g.</p>
  <pre><code>arr = [1, 2, 3, 0, 2, 1, 3]
  stack = [3, 1, 2]
  </code></pre>
  <p>Here, 1,2, and 3 are the repeated elements and 2 appear before all other repeated elements that's why it is at the top of stack, then 1 which comes before 3 then lastly 3</p>
  <p>another example</p>
  <pre><code>arr = [1,2,0,2,3,0,1]
  stack = [1, 0, 2]
  </code></pre>
  <p>you may assume elements are repeated only twice.</p>