Hello everyone, I recently had my online assessment for new grad role at google. I want to post a question which was asked, and seek help from the community in solving this problem. The problem was:
PR Strings
You are given a string S (consisting of lowercase English characters).
In one operation, you can remove the substring "pr" from the string S and get the 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 perfrom zero or more such operations optimally.
Note:
Input format
Output
Example
Sample Input
3
abppprrr
5 4
prprprrp
7 10
abcdpqrpqr
3 4Sample Output
15
37
4Explanation:
Test Case 1:
S = "abppprrr", X=5, Y=4
Remove substrings as mentioned:
In total we remove "pr" 3 times. Hence answer is 3*X=15.
Test Case 2:
S = "prprprrp", X=7, Y=10
Remove substrings as mentioned:
In total we remove "rp" 3 times and "pr" 1 times. Hence answer is 3Y + 1X = 37.
Sample python function:
def solve(S, X, Y):
#Code goes hereThanks in advance.