diff --git a/AnagramPeriod/AnagramPeriod.class b/AnagramPeriod/AnagramPeriod.class index 3a84486..296ea2d 100644 Binary files a/AnagramPeriod/AnagramPeriod.class and b/AnagramPeriod/AnagramPeriod.class differ diff --git a/AnagramPeriod/AnagramPeriod.java b/AnagramPeriod/AnagramPeriod.java index 9310ef4..fdccbc3 100644 --- a/AnagramPeriod/AnagramPeriod.java +++ b/AnagramPeriod/AnagramPeriod.java @@ -1,12 +1,42 @@ +import java.util.Scanner; public class AnagramPeriod { public static void main(String[] args) { - getAnagramPeriod("ababbaab"); + Scanner sc = new Scanner(System.in); + String a = sc.nextLine(); + String b = sc.nextLine(); + sc.close(); + + int totalDel = makeAnagram(a, b); + System.out.println(totalDel); + } - private static void getAnagramPeriod(String input_str) { - int n = input_str.length(); - System.out.println(n); + private static int makeAnagram(String strOne, String strTwo) { + // bacdc + // dcbac + // bacdc + // dcbad + + int[] a_frequency = new int[26]; // 26 numbers of letters in the alphabet. + int[] b_frequency = new int[26]; // 26 numbers of letters in the alphabet. + + // populate the frequence array for String strOne + for (char c : strOne.toCharArray()) { + a_frequency[c - 'a']++; + } + + // populate the frequence array for String strTwo + for (char c : strTwo.toCharArray()) { + b_frequency[c - 'a']++; + } + + // calculate the total number of deletions needed + int deletion = 0; + for (int i = 0; i < 26; i++) { + deletion += Math.abs(a_frequency[i] - b_frequency[i]); + } + return deletion; } } diff --git a/test-results/.last-run.json b/test-results/.last-run.json new file mode 100644 index 0000000..5fca3f8 --- /dev/null +++ b/test-results/.last-run.json @@ -0,0 +1,4 @@ +{ + "status": "failed", + "failedTests": [] +} \ No newline at end of file