title: Suggest an optimal algorithm for the sum of distances of the first match in two seqence
body: <p>I have two list say L1 and L2, (minimum) sum of the lengths of the two lists.</p>
  
  <p><strong>For Example:</strong></p>
  
  <p>89 145 42 20 4 16 37 58 89</p>
  
  <p>20 4 16 37 58 89 </p>
  
  <p><strong>Output : 5</strong></p>
  
  <p>89 145 42 20 4 16 37 58 89</p>
  
  <p>56 678 123 65467</p>
  
  <p><strong>Output : 0</strong></p>
  
  <p>19 82 68 100 1</p>
  
  <p>100 1 </p>
  
  <p><strong>Output : 5</strong></p>
  
  <p>Thanks,</p>
  
  <p>PS: My language of choice is C and C++ hence the tag.</p>