For a given string S, the function change (n, m) replaces all 'n' with 'm' in string S. For example, if S = "alopecia", change (a, b) will give the string "blopecib". You need to find the minimum number of uses of change (n, m) such that the string S forms a palindrome. I'm looking for a O(length(S)) solution. Preferably JAVA.
// Code to copy
// Create class
public class MinChange
{
// create method to find the minimum number
// character change required
public static void minchange(char[] s)
{
// Finding the length of the string
int n = s.length;
// To store the number of replacement operations
int count = 0;
for(int i=0;i<n/2;i++)
{
// If the characters at location i and n-i-1 are same then
// no change is needed
if(s[i]== s[n-i-1])
continue;
// Counting one change operation
count+= 1;
// change(n,m) function part
// Changing the character with higher
// ascii value with lower ascii value
if(s[i]<s[n-i-1])
s[n-i-1]= s[i] ;
else
s[i]= s[n-i-1] ;
}
System.out.println("Minimum characters to be replaced = "+count);
System.out.println(s);
}
// create main method (driver code)
public static void main(String[] args)
{
String s = "ceeks";
char[] schar = s.toCharArray();
minchange(schar);
}
}
// screenshot of the code


// screenshot of the output

// In case of any query, you can ask in comment
// thanks
For a given string S, the function change (n, m) replaces all 'n' with 'm' in...
Given a string S that contains lowercase English letters representing different types of candies. A substring of a string S is a string Ssub that occurs in S. For example, "twix" is a candy name which is the substring of "twtwixtwixnerdstwixnerds". Each candy costs 1 unit. You can pick some consecutive candies such that you can create a palindrome of length L by using some or all picked candies while the number of all possible cases K (all possible palindromes)...
Palindromes A palindrome is a nonempty string over some alphabet that reads the same forward and backward. Examples of palindromes are all strings of length 1, civic, racecar, noon, and aibohphobia (fear of palindromes). You may assume that in the problems below, an input string is given as an array of characters. For example, input string noon is given as an array s[L.4], where s[1] = n, s[2] = o, s[3] = o, and s[4] = n. (a) (15 pts)...
Please i need programs in C 32) Write a function that, given a string, a width, and an empty string for output, centers the string in the output, centers the string in the output area. The function is to return 1 if the formating is successful and 0 if any errors, such as string length greater than width, are formed. 35) Write a function called newStrCmp that does the same job as strcmp. The declaration for your functions is to...
Write a function that determines if a string has the same number of 0’s and 1’s using a stack. The function must run in O(N) time. You can assume there already exists a stack class and can just use it (Java Please)
please implement this function by C language
Write a string compare function which returns 1 if the strings match for n characters starting at offset m, O if the strings don't match. You must check if m is within the length of both s and t. int submatch(char* s, char* t, int n, int m)
Write a string compare function which returns 1 if the strings match for n characters starting at offset m, O if the strings don't match....
pUI) FOU are to write a function which has a prototype: void count (char sl, int *pUpper, "pLower, "poigit, pother) s [ is a character string which may be of any length. Other arguments are address of where the number of upper, lower, digits, and other characters in the string should be placed. For example (this is only an example) the code (put into a properly written program): char all "12145-9ABD, 3f0 :bbB2" char bll "148x3!!" char c[] = {...
Give a recursive formula for the function g(n) that counts the number of ternary strings of length n that do not contain 2002 as a substring. You do not need to find a closed form solution for g(n).
Programming language: Java m: substring length n: input strings d: Hamming distance (mismatch) I: Number of letters in Sample input string (s1, s2, s3) Strings consists of: A, C, G, and T Example outputs: Generate all possible possibilities of length m(4) using the values A, C, G, and T. EX possibilites: {A,A,A,A A,A,A,C.... G,G,G,G} and find all the possible combinations that have the same sequence with a hamming distance of 1 (only 1 difference) Given n input strings of length...
(3.5) Summing the Euler S-function (n): The Euler 6-function 6(n) counts the number of positive integers less than or equal to n, which are relatively prime with n. Evaluate 4(d), and prove that your answer is correct. (3.4) Relatively Prime Numbers and the Chinese Re- mainder Theorem: Give an example of three positive integers m, n, and r, and three integers a, b, and c such that the GCD of m, n, and r is 1, but there is no...
Given two functions, M(x, y) and N(x,y), suppose that ON/ that an/az-amay is M-N a function of x +y. That is, let f(t) be a function such that ON _ OM dc du f(x+y) = M-N Assume that you can solve the differential equation Mdx + Ndy = 0 by multiplying by an integrating factor u that makes it exact and that it can also be written as a function of x + y, u = g(x + y) for...