@@ -0,0 +1,1645 @@
+import java.util.Arrays;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class IsOneStringAPermutationOfAnother %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09%0A%09%09// Given two strings, write a method to decide if one is a permutation%0A%09%09// of another. %0A%0A%09%09// what is a permutation?%0A%09%09// well, since these are strings, you could just consider%0A%09%09// this to be an anagram test...%0A%09%09%0A%09%09// they contain the same chars in the same quantities%0A%09%09String a1 = %22abcdef%22;%0A%09%09String b1 = %22bcafed%22;%0A%09%09%0A%09%09String a2 = %22abcdef%22;%0A%09%09String b2 = %22acbddf%22;%0A%09%09%0A%09%09// what about case sensitivity? %0A%09%09// what about whitespace? %0A%09%09%0A%09%09System.out.println(isPerm(a1, b1));%0A%09%09%0A%09%09System.out.println(isPerm(a2, b2));%0A%09%09%0A%09%7D%0A%09%0A%09%0A%09%0A%09public static boolean isPerm(String a, String b) %7B%0A%09%09// quick short-circuit check.%0A%09%09if(a.length() != b.length()) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09%0A%09%09// n * log(n) soln%0A//%09%09char %5B%5D arr1 = a.toCharArray();%0A//%09%09Arrays.sort(arr1);%0A//%09%09char %5B%5D arr2 = b.toCharArray();%0A//%09%09Arrays.sort(arr2);%0A//%09%09%0A//%09%09return (new String(arr1)).equals(new String(arr2));%0A%09%09%0A%09%09%0A%09%09// linear soln (n)%0A%09%09Map%3CCharacter, Integer%3E charMap = new HashMap%3C%3E();%0A%09%09for(char c : a.toCharArray()) %7B%0A%09%09%09if(charMap.containsKey(c)) %7B%0A%09%09%09%09charMap.put(c, charMap.get(c) + 1);%0A%09%09%09%7D else %7B%0A%09%09%09%09charMap.put(c, 1);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09for(char c : b.toCharArray()) %7B%0A%09%09%09if(charMap.containsKey(c)) %7B%0A%09%09%09%09charMap.put(c, charMap.get(c) - 1);%0A%09%09%09%7D else %7B%0A%09%09%09%09// if we are missing something in the 2nd string%0A%09%09%09%09// that we had in the first.%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09//%0A%09%09for(int i : charMap.values()) %7B%0A%09%09%09if(i != 0) %7B%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09// 3 * n --%3E n %0A%09%09%0A%09%09return true;%0A%09%7D%0A%0A%09%0A%09%0A%09%0A%09%0A%7D%0A

Create IsOneStringAPermutationOfAnother.java