#106 Custom List Sorting by the Prefix of Another List

Companies:
Unidata
Themes:
AlgorithmsSortingPractice

There are two lists, m1 and m2. Sort m2 so that the elements from m1 appear at the beginning, followed by all remaining elements sorted in natural order:

public class Main
{
    public static void main(String[] args) {
        List<Integer> m1 = Arrays.asList(5, 3, 0);
        List<Integer> m2 = new ArrayList<>(Arrays.asList(7, 3, 5, 2, 9, 8, 4, 1, 6));

        List<Integer> result = customSort(m1, m2);

        System.out.println(result); // [5, 3, 1, 2, 4, 6, 7, 8, 9]
    }

    public static List<Integer> customSort(List<Integer> m1, List<Integer> m2) {
        ...
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in