Question: Problem statement Send feedback You are given a string ' S ' of length ' N ' and an integer ' K ' . '

Problem statement
Send feedback
You are given a string 'S' of length 'N' and an integer 'K'.'K' is a divisor of 'N'.
Suppose you break the string into 'M' subarrays (where 'M'=?'N'/'K'), i.e.,
The first substring 'S1' is 'S[1dotsK]'.
The second substring 'S2' is 'S[K+1dots2***K]'.
...
The 'M'th substring is 'SM' is '*[:K}'.
You are allowed to do the following operation:
Choose any index 'i' of the string 'S'.
Replace it with any lowercase character. The cost of this operation is '1.:
Your task is to convert the string 'S' such that:
All the characters in a substring are same for each of the 'M' substrings.
Any two consecutive substrings do not have the same character.
Your task is to find the minimum cost to do so and return it.
Note:
For a string 'S',S[i...j] denotes the string 'S' substring from index 'i' to index 'j].
 Problem statement Send feedback You are given a string 'S' of

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!