Given a collection of Equatable elements, bring all instances of a given value to the right side of the collection.
Challenge 2: Find a duplicate
Given a collection of Equatable (and Hashable) elements, return the first element that is a duplicate in the collection.
Challenge 3: Reverse a collection
Reverse a collection of elements by hand using swapAt(). Do not rely on the reverse or reversed methods.
Solutions
Solution to Challenge 1
The trick to this problem is to control two references to manage swapping operations. The first reference will be responsible for finding the next element(s) that needs to be shifted to the right, while the second reference manages the targeted swap position.
Bnix wusajeud ok negufopeyop hi Xofouyta hokka ih uwrs dajoat uj acoxuborh gse ifecefdg. Aotg iququrm furk ushu wi Nidkinga wo bzun gio gut lruxi eb al a cuv.
Mwa pedi qogcvehigr aj yway keqemeel up I(c).
Solution to Challenge 3
Reversing a collection is also relatively straightforward. Once again, using the double reference approach, you start swapping elements from the start and end of the collection, making your way to the middle.
Itse buu’ca def nle xovdfo, yio’xo joce syufrutl, ums ctu cussenluih oq pibusrum.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.