Skip to content

Instantly share code, notes, and snippets.

@ohmslaw
Last active November 11, 2016 15:38
Show Gist options
  • Save ohmslaw/120870839e4d92dd34a4bd27e624dd62 to your computer and use it in GitHub Desktop.
Save ohmslaw/120870839e4d92dd34a4bd27e624dd62 to your computer and use it in GitHub Desktop.
import java.util.*;
class Main {
public static void main(String[] args) {
// Assume we are provided a list of already sorted values (size between 10-10000)
List<Integer> existingItems = generateRandomList(1000);
Collections.sort(existingItems);
// Assume you would be given items to add to the list (size between 1-5)
List<Integer> newItems = generateRandomList(3);
// TODO: Insert new items into the list in order without using sort.
addItemsToSortedList(existingItems, newItems);
}
private static void addItemsToSortedList(List<Integer> sortedList, List<Integer> newItems) {
// Add code.
}
// This is for a bit of random data, no need to worry about this method.
private static List<Integer> generateRandomList(int size) {
List<Integer> list = new ArrayList<>();
for(int i=0; i<size; i++){
list.add((int) (Math.random() * 1000000));
}
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment