#106 Custom List Sorting by the Prefix of Another List
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
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor