O(n) implementation of the C Sample Algo

Number of iteration for the two implementations:
   input1: 37 O(n) / 2 O(n2)
   input2: 16 O(n) / 1 O(n2)
   input3: 12 O(n) / 6 O(n2)
   input4: 36 O(n) / 45 O(n2)
   input5: 76 O(n) / 190 O(n2)