MakeAnagram
This commit is contained in:
Binary file not shown.
@@ -1,12 +1,42 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class AnagramPeriod {
|
public class AnagramPeriod {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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) {
|
private static int makeAnagram(String strOne, String strTwo) {
|
||||||
int n = input_str.length();
|
// bacdc
|
||||||
System.out.println(n);
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"status": "failed",
|
||||||
|
"failedTests": []
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user