Question: public class Solution { static int findMinCost ( int n , int k , String s ) { int m = n / k; int

public class Solution {
static int findMinCost(int n, int k, String s){
int m = n / k;
int totalCost =0;
for (int i =0; i < k; i++){
int[] charCount = new int[26]; // Assuming lowercase English letters
for (int j = i; j < n; j += k){
charCount[s.charAt(j)-'a']++;
}
int maxCount =0;
for (int count : charCount){
maxCount = Math.max(maxCount, count);
}
totalCost +=(m - maxCount);
}
return totalCost;
}
public static void main(String[] args){
int t =2;
int n1=93, k1=3;
String s1= "khkkdkuki";
System.out.println(findMinCost(n1, k1, s1)); // Output: 5
int n2=93, k2=3;
String s2= "kegohsirj";
System.out.println(findMinCost(n2, k2, s2)); // Output: 6
}
} i want this code in different way

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!