title: Determing if two lists contain the same numeric items without sorting
body: <p>I have two lists and I need to determine if they contain the same values without sorting (ie. order of values is irrelevant). <strong>I know sorting the would work, but this is part of a performance critical section.</strong></p>
  
  <p>Item values fall within the range [-2, 63] and we're always comparing equal size lists, but the list sizes range from [1, 8].</p>
  
  <p>Example lists:</p>
  
  <pre><code>A = (0,   0, 4, 23, 10)
  B = (23, 10, 0,  4,  0)
  C = (0,   0, 4, 27, 10)
  
  A == B is true
  A == C is false
  </code></pre>
  
  <hr>
  
  <p>I think a possible solution would be to compare the product of the two lists (multiply all values together), but there are problems with this solution. What to do with zero and negative numbers. A workaround would be adding 4 to every value before multiplying. Here's the code I have so far.</p>
  
  <pre><code>bool equal(int A[], int B[], int size)
  {
      int sumA = 1;
      int sumB = 1;
  
      for (int i = 0; i &lt; size; i++) {
          sumA *= A[i] + 4;
          sumB *= B[i] + 4;
      }
      return (sumA == sumB)
  }
  </code></pre>
  
  <p>But, would this always work no matter what the order/contents of the list were? In other words is the following mathematically true? So what I'm really asking is the following (unless there's another way to solve the problem):</p>
  
  <p><strong>Given 2 equal sized lists. If the products (multiplying all values together) of the lists are equal then the lists contain the same values, so long as the values are integers greater than 0.</strong></p>