title: Iterate over two list to get index location
body: <p>I am trying to find efficient approach to traverse two lists and return indexes of the second list based on the match between the elements in both the list. The indexes are then used to lookup data from another array so second list essentially holds position for the array.</p>
  
  <p>Both List are of type RowType where</p>
  
  <pre><code>public class RowType 
  {
      public int Type; //Acts as a group
      public int SubType; //Specific classification of the type
  }
  </code></pre>
  
  <p>My current approach is to iterate over the first list and then for each element, iterate over the second list comparing Type or Type\Subtype combination to get the index. This is essentially O(n*m) which is dragging down the overall performance. </p>
  
  <p>List1 can contains combination of RowType elements where <strong>only Type is specified or Type and SubType both</strong>.</p>
  
  <p>List2 contains elements which has <strong>both Type and SubType</strong>.</p>
  
  <p>In example below T1 and T2 are two types and R1 to R16 are SubType. SubType are unique across Type. So R1 is a subtype for T1 then no other type will have R1 as subtype.</p>
  
  <pre><code>Input
      List&lt;RowType&gt; list1 = new List&lt;RowType&gt;(){ T1, T2, RT3 }
      List&lt;RowType&gt; list2 = new List&lt;RowType&gt;(){ RT1, RT3, RT6, RT7, RT9 }
  
      where 
      RT1 -&gt; Type = T1, SubType = R1
      RT3 -&gt; Type = T3, SubType = R3
      RT6 -&gt; Type = T1, SubType = R6
      RT7 -&gt; Type = T2, SubType = R7
      RT9 -&gt; Type = T4, SubType = R9
  
  Expected Output
      0, 1, 2, 3  
  
  Index 0 since T1 is Type for RT1
  Index 2 since T1 is Type for RT6
  Index 3 since T2 is Type for R7
  Index 1 since RT3 matches RT3
  </code></pre>