Question: By the time Agent P breaks into the evil Dr . D ' s private office, Dr . D changes his computer's password and manages

By the time Agent P breaks into the evil Dr. D's private office, Dr. D changes his computer's password and manages to escape.
Dr. D changed some random letters in the original password to make the new password; therefore, the new password is the same length as the old one (there is no insertion or deletion of characters).
The password is a string of characters, with the only possible characters being the small letters from the English alphabet ('a' to 'z').
Agent P knows that the new password is k-balanced. A string is k-balanced if all the substrings of length k have the same counts of all the 26 letters ('a' to 'z')(see samples for more details).
A string A is a substring of a string B if A can be obtained from B by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. For example, 'c', 'fish', 'cat', 'atf', 'is',..., are substrings of 'catfish', but 'z', 'cis', 'cats',..., are not.
He also believes that Dr. D was in a hurry and could not have changed many characters.
So, he wants to know the minimum number of changes required in the old password to make it k- balanced.
Given a string password and an integer k. Help Agent P by calculating the minimum number of changes required in password so that the new password is k-balanced.
Input Format
The first line contains an integer, k, denoting the integer described in the problem statement
The next line contains a string, password, denoting the old password
Constraints
1<= k <= len(password)
1<= len(password)<=10^5
Case 1:
Input:
5
bdbab
Output: 0
Explanation:
k =5 password = "bdbab" all the k-length substrings =["bdbab"} The count of each character is already the same in all the k-length substrings.
case: 2
Input: baacb
Output:2
Explanation:
k =4 password = "baacb" all the k-length substrings ={"baac", "aacb"} count of letters in "baac" is {"a"=2,"b"=1,"c"=1

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!