Alternative solution in comment

Alternative solution for sorting the array added in comment