rewrite linear solution for insertionSort