Is there an efficient way to sort a list of integers such that each consecutive one has a low number of bits different from the last? I came up with an O(n^2) algorithm to do it but I'm hoping there's a better way.
remove_at is O(n), assuming "in" is a list, so you're still at O(n^2) overall. Could potentially get a constant-factor speedup using some kinda iterable hashset. (I think you'll find O(n*tri(n)) is the same as O(n^2) in practice, anyway)
-
-
Tried the hashset trick on indices to avoid list removal, takes longer in practice to iterate the hashset than it does to remove the list items.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.