Last active
November 11, 2016 15:38
-
-
Save ohmslaw/120870839e4d92dd34a4bd27e624dd62 to your computer and use it in GitHub Desktop.
Insert - https://repl.it/DwWQ/5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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