// Remove duplicates
while (arr[i] == arr[i+1])
i++;
}
return prod;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
int count1=0;
while(t--)
{
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
You are given a string S of lowercase English letters with length N. You are allowed to (but don't have to) choose one index in this string and change the letter at this index to any other lowercase English letter. The cost of this operation is the absolute value of the difference of ASCII values of the new letter and the original letter; let's denote it by X.
Next, consider the number of pairs of indices (i,j) in the resulting string (the string after changing one letter, or the original string if no letter was changed) such that 1≤i<j≤N and Si<Sj. Let's denote it by Y.
I have done the No Strings Attached.If anyone has solution of questions after question-4 [even partial is okay] then pm me i will tell him the logic for No Strings Attached[or will send the code]
Since everyone was asking the logic for no strings attached question i will share here some of the hints:
first understand the question.
You can change the letter[or not] in the given string.
So if you are given a string with consecutive letters then your answer is just min(y),
but if some of your character is not in consecutive then change it to min possible and in that case your answer is min(x+y)
Hint: for comparision you can use balanced binary search tree [ To avoid TLE problems]
[If you know c++ -stl then you can use map which is built based on balanced bst only]