Sort one sequence by O(n) in time and O(1) in space

Oscar Benjamin oscar.j.benjamin at gmail.com
Sun Feb 9 08:41:35 EST 2014


On 9 February 2014 12:13, Wesley <nispray at gmail.com> wrote:
> Hi guys,
>    Here is one question related to algorithm.
> Details here:
>
> here is input sequence like a1,a2,...,an,b1,b2,...,bn ,the ax and bx always exist in pair. So, now, how to change the sequence to a1,b1,...,an,bn, with time complexity as O(n) and space as O(1).

Do you mean that you have a list and you want to rearrange the
elements in-place without creating a new list?


Oscar



More information about the Python-list mailing list