Problem #1 -- ArrayList Mystery [-5, 6, 8] [1, 6, 2, 10] [5, 1, 15, 3, 7, 42] [9, 7, 5, 3, 1, 8, 4, 2, 6, 10] Problem #2 -- Recursive Tracing 0-1 4-2-0-1-3 8-6-4-2-0-1-3-5-7-9 Problem #3 -- ListNode Manipulation One possible solution for each subproblem: Subproblem #1 ListNode temp2 = temp; temp = list.next; list.next = temp2; Subproblem #2 temp.next.next = list; // 4 -> 1 list.next.next = temp; // 2 -> 3 list = temp.next; // list -> 4 temp.next = null; temp = null; Subproblem #3 temp.next = list.next.next; // 4 -> 3 temp.next.next = list; // 3 -> 1 list = temp; // list -> 4; temp = list.next.next.next; // temp -> 2 temp.next = null; list.next.next.next = null; Problem #4 -- Stacks and Queues One possible solution: public static void separate3(Queue q) { Stack s = new Stack(); int size = q.size(); // q = [5, 28, 6, 11, 2, 9, 7, 0, 42, 14, 92, 37] for (int i = 0; i < size; i++) { int num = q.remove(); if (num % 3 == 0) { s.push(num); } else { q.add(num); } } // q = [5, 28, 11, 2, 7, 14, 92, 37] // s = [6, 9, 0, 42] size = q.size(); for (int i = 0; i < size; i++) { int num = q.remove(); if (num % 3 == 1) { s.push(num); } else { q.add(num); } } // q = [5, 11, 2, 14, 92] // s = [6, 9, 0, 42, 28, 7, 37] q2s(q, s); // s = [6, 9, 0, 42, 28, 7, 37, 5, 11, 2, 14, 92] s2q(s, q); q2s(q, s); s2q(s, q); } } Problem #5 -- ArrayIntList One possible solution public void retainAll(Set s) { for (int i = 0; i < size; i++) { if (!s.contains(elementData[i])) { for (int j = i; j < size - 1; j++) { elementData[j] = elementData[j + 1]; } size--; i--; } } } Problem #6 -- Collections public Map> deepCopy(Map> map) { Map> copy = new TreeMap>(); for (String key : map.keySet()) { List list = map.get(key); List newList = new ArrayList(); for (int n : list) { newList.add(s); } copy.put(key, newList); } return copy; } Problem #7 - Recursive Programming One possible solution: public static boolean sameDashes(String s1, String s2) { if (s1 == null || s2 == null || s1.length() != s2.length()) { throw new IllegalArgumentException(); } if (s1.length() == 0) { return true; } else { if (s1.charAt(0) == '-' && s2.charAt(0) != '-') { return false; } if (s1.charAt(0) != '-' && s2.charAt(0) == '-') { return false; } return sameDashes(s1.substring(1), s2.substring(1)); } }