Question
Write simple python/java program and also explain the logic because i am crying so much and not able to understand anything. A Special String: You
Write simple python/java program and also explain the logic because i am crying so much and not able to understand anything.
A Special String: You are given a string S consisting of lowercase Latin alphabets a-z. Find the minimum number of characters that must be changed to make S special. A string S is said to be special if and only if for all (S[i] , S[j] ) where (1 i N/2) and (N/2 + 1 j N) one of the following condition is true
- S[i] > S[j]
- S[i] < S[j]
- S[i] = S[j]
S[i] represents the ith character of string S (1 based Indexing ).
Input Format:
- The first line contains an integer T denoting the number of test cases.
- The first line of each test case contains an integer N denoting the length of S.
- The second line of each test case contains a string S.
Output format: Print an integer denoting the minimum number of changes required for each test case in a new line.
Constraints
1 T 5
1 N 103
N is even
Example :
Input: 1 6 aababc Output: 2
Explanation: Change S[4] = d (1 based indexing) Change S[5] = d New string = aabddc Now all pair (S[i],S[j]) satisfy the second condition, S[i] < S[j]
Generating Sequence: You are given two strings A of length N and B of length M. These strings contain lowercase English alphabets. You are also given an integer K. You can change the character of x string A to any other characters y. The cost of this conversion is abs( ASCII(x)- ASCII(y) ). Find the minimum cost required such that the length of the longest common subsequence (LCS) of A and B is at least K.
Note:
- A subsequence of A string can be obtained by deleting zero or more characters in A.
- The longest common subsequence of two strings of A and B is a subsequence of A and B and has the maximum length among all strings that are a subsequence of A and B that would be multiple subsequences for two provided strings for example an LCS of vera and eats is ea.
Input Format:
- The first line contains an integer T denoting the number of test cases for each test case.
- The first line of each test case contains three space-separated integers N, M, and K.
- The next line of each test case contains a string A.
- The next line of each test case contains a string B.
Output format: For each test case, print the minimum cost required in a new line.
Constraints
1 T 10
1 N, M 200
0 K min( N, M )
Example:
Input: 2 5 4 3 abcba acyx 3 3 3 abc abc Output: 22 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started