Question: Fair String Given a binary string S of size N. You had been given the task to convert the given string into Fair string. 15
Fair String Given a binary string S of size N. You had been given the task to convert the given string into Fair
string.
15 };
16
17
You can do the following operation any number of times:
. If the ith character in S is 0, replace it with 1 using cost C[i].
. If the ith character in S is 1, replace it with 0 using cost C[i].
You have to determine the minimum cost used to convert the given string into Fair string.
A string S is a Fair string if it is either of type
XYXYXYXYXY.....or,
XXYYXXYYXXYY...
Binary strings are string that only contains '0' and '1'.
Note: N is of even length.
Example 1:
Input:
N = 4
S-0101
C[N]={1,2,1,3}
Output:
0
Explanation:
Given string is already fair string since it is of type XYXYXYXY.....
Example 2:
Input:
N = 4
S = 0010
C[N]=(1,0,4,0}
Output:
0
Explanation:
Replacing last character with 1 will cost
Your Task:
You don't need to read, input, or print anything. Your task is to complete the function solve( ), which takes N, String S, and Cost array C[ ] as input parameters and returns the answer.
Constraints:
2N2*10^5 0C[i] 10^4




obierns Fair string Accuracy: 100.0% Submissions: 2 Points: 30 Given a binary string S of size N. You had been given the task to convert the given string into Fair string. You can do the following operation any number of times : If the ith character in Sis 0, replace it with 1 using cost c[i]. If the ith character in S is 1, replace it with O using cost c[i]. You have to determine the minimum cost used to convert the given string into Fair string. A string S is a Fair string if it is either of type 8 XYXYXYXYXY..... or, XXYYXXYYXXYY... Binary strings are string that only contains 'O' and 'l'. Note: N is of even length. Example 1: Input: N = 4 Fair string Accuracy: 100.0% Submissions: 2 Points: 30 Given a binary string S of size N. You had been given the task to convert the given string into Fair string. You can do the following operation any number of times : If the ith character in S is 0, replace it with 1 using cost C[i]. If the ith character in Sis 1, replace it with O using cost c[i]. You have to determine the minimum cost used to convert the given string into Fair string. A string S is a Fair string if it is either of type e XYXYXYXYXY..... or, XXYYXXYYXXYY... Binary strings are string that only contains 'O' and 'l'. Note: N is of even length. Example 1: Input: N = 4. = Fair string Accuracy: 100.0% Submissions: 2 Points: 30 N = 4 S=0101 C[N]={1,2,1,3} Output: 0 Explanation: Given string is already fair string since it is of type XYXYXYXY.... Example 2: Input: N. = 4 S = 0010 C[N]={1,0,4,0} Output: 0 Explanation: Replacing last character with 1 will cost 0 and that will make our string fair string Accuracy: 100.0% Submissions: 2 Points: 30 Input: N = 4 S = 0010 C[N]={1,0,4,0} Output: Explanation: Replacing last character with 1 will cost o and that will make our string fair string with type XXYYXXYYXXYY..... Your Task: You don't need to read, input, or print anything. Your task is to complete the function solve ), which takes N, String S, and Cost array C[las input parameters and returns the answer. Constraints: 2 SNS2*105 03C[i] =104
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
