Google | OA 2021 | PR Strings

Location : India
Position : Software Engineer III

There are total two questions to attempt within 60 minutes of time.

PR Strings

Problem Statement :
You are given String S of lowercase alphabets. In one operation, you can remove the substring "pr" from the string S and get amount X or you can remove the substring "rp" from the string S and get the amount Y.

Find the maximum amount you can get if you perform zero or more such operations optimally.

Input Format
First Line contains number of testcase T.
First line of each testcase contains a string S
Second line contains two spaced integers X and Y

Sample Input

3
abppprrr
5 4
prprprrp
7 10
abcdpqrpqr
3 4

Sample Output

15
37
4

Explaination
Testcase 1 -
Remove "pr", S becomes "abpprr".
Remove "pr", S becomes "abpr".
Remove "pr", S becomes "ab".
Hence - 3x5 = 15

Testcase 2 -
Remove "rp", S becomes "prprrp"
Remove "rp", S becomes "prrp"
Remove "rp", S becomes "pr"
Remove "rp", S becomes " "

Constraints
1 <= T <= 10
1 <= |S| <= 100000
1 <= X <= 100
1 <= Y <= 100

Comments (4)