Skip to content

Instantly share code, notes, and snippets.

@ramonaharrison
Last active February 25, 2017 15:16
Show Gist options
  • Save ramonaharrison/bcf9e1b4b78dc279fade81682779ed62 to your computer and use it in GitHub Desktop.
Save ramonaharrison/bcf9e1b4b78dc279fade81682779ed62 to your computer and use it in GitHub Desktop.

Morning Challenge

1) Given an string, write a method called HashMap<String, Integer> countTheLetters(String input) that returns a map containing a count for each of each of the letters in the string. For full credit, your solution should be O(n).

countTheLetters("dog"); // returns a map containing the pairs {d: 1, o: 1, g: 1}
countTheLetters("elephant"); // returns a map containing the pairs {e: 2, l: 1, p: 1, h: 1, a: 1, n: 1, t: 1}
countTheLetters("llama"); // returns a map containing the pairs {l: 2, a: 2, m: 1}



2) Given an array of integers, write a method called int[] removeDupes(int[] input) that returns a new array of just the unique values. You may use additional data structures in your solution.

removeDupes(new int[]{1, 2, 3, 4, 5, 1, 2, 3}); // returns {4, 5}
removeDupes(new int[]{7, 7, 7, 7, 7}} // returns {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment