Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
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
Comments
Rick York 22-Feb-21 12:01pm    
Why is this tagged for C? It has nothing to do with C.

1 solution

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.
Your requirement is:
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.
 
Share this answer
 
v2

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



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