How can I sort the elements of the list A so that they follow the ordering of another (superset) list B? Assume no duplicates.
E.g. A might contain [8 2 5 1] and B might contain [5 6 9 8 7 4 1 2 3], and so I'd like to sort A to become [5 8 1 2]
I'm interested in ways of doing this efficiently and with good runtime complexity.