adding old solved challenges

This commit is contained in:
2024-10-15 11:03:57 -04:00
parent fa5ac5e089
commit 7ecd444efb
107 changed files with 1056 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import java.util.HashMap;
import java.util.Map;
public class failedTest {
public static int getAnagramPeriod(String input_str) {
int len = input_str.length();
Map<Character, Integer> freqMap = new HashMap<>();
// Count the frequency of each character in the input string
for (char c : input_str.toCharArray()) {
freqMap.put(c, freqMap.getOrDefault(c, 0) + 1);
}
int period = freqMap.size(); // Anagram period initially equals the count of unique characters
return period;
}
public static int getSmallestPossibleStringLength(String input_str) {
int period = getAnagramPeriod(input_str);
int len = input_str.length();
return len / period;
}
public static void main(String[] args) {
String input = "abbbabbabababbbbbaaaaaaababa"; // Replace this with your input string
int smallestLength = getSmallestPossibleStringLength(input);
System.out.println("The length of the smallest possible string is: " + smallestLength);
}
}