title: Find ascending duplicate pairs in an array
body: <p>Given an array A with zero index and N integers find equal elements with different positions in the array. Pair of indexes (P,Q) such that 0 &lt;= P &lt; Q &lt; N such that A[P] = A[Q]. My algorithm is below but I am looking for a O(N*logN) solution.</p>
  
  <pre><code>    public int solution(int[] A)
      {
          int N = A.Length;            
          int count = 0;
  
          for (int j = 0; j &lt; N; j++)
          {
              count += FindPairs(A[j], j, A);
          }
  
          return count;
      }
  
      public int FindPairs(int item, int ci, int[] A)
      {
          int len = A.Length;
          int counter=0;
          int k = ci+1;
          while (k &lt; len)
          {
              if (item == A[k])
                  counter++;
              k++;
          }
          return counter;
      }
  </code></pre>