15,035,723 members
1.00/5 (1 vote)
See more:
Given an arr, of size N and a string of site N the string is only consisting of x and y. You can select a substrtng with all equal characters and delete them and you will get the score i.e A[len] if len is the length of the substring deteted
Note: The array of scorA has 1 based indexing Find the max score than can be attained
Function Description
Complete the solve function in the editor below It has the following parameter(s)-

Parameters

N 'INTEGER
str STRING
arr 1 INTEGER ARRAY

Return The function must return an INTEGER denoting the max score

example:

Input
1

x

1024

output
1024

What I have tried:

Python
```def cal(A,s):
x=s.count('x');
y=s.count('y');
if(x>y):
return max(A[0::x]);
else:
return max(A[0::y]);

n=int(input());
s=input();
A=list(map(int,input().split()));```
Posted
Updated 22-Feb-21 0:15am
v2
Rick York 22-Feb-21 12:01pm

Why is this tagged for C? It has nothing to do with C.

Solution 1

Your code is incomplete, but:
Python
```def cal(A,s):
x=s.count('x');
y=s.count('y');
if(x>y):
return max(A[0::x]);
else:
return max(A[0::y]);```

Here, you are counting all 'x' and all 'y' in the string, which is wrong.
Quote:
You can select a substring with all equal characters and delete them and you will get the score i.e A[len] if len is the length of the substring deteted

Example:
```xyxyxxyyxxyyyyxyxyxyx
^^^^ this is the substring of maximum length with all equal chars```

You have to search where is that substring.
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 128 Richard Deeming 60 Dave Kreskowiak 45 KarstenK 25 Richard MacCutchan 20
 OriginalGriff 2,955 Richard Deeming 1,783 Richard MacCutchan 1,590 CPallini 1,003 Dave Kreskowiak 731

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900