Problem Statement
At Amazon, a user owns a unique tool called the "Parentheses Perfection Kit." This kit contains different types of parentheses, each with a specific efficiency rating. The goal is to create a balanced sequence of parentheses by adding zero or more parentheses from the kit to maximize the sequence's total EfficiencyScore. The EfficiencyScore of a sequence is the sum of the efficiency ratings of the parentheses used from the kit.
Definition of a Balanced Sequence:
A sequence is considered balanced if:
- It has an equal number of opening
(
and closing)
parentheses. - Each opening parenthesis is properly matched with a closing one in the correct order (i.e., circular balance).
Examples of balanced sequences:
()
(())
(()())
Examples of unbalanced sequences:
)
(()
(()(()))
Input Details:
- An initial parentheses sequence represented by the string
s
. - A Parentheses Perfection Kit containing:
kitParentheses
: Different types of parentheses.efficiencyRatings
: Their respective efficiency ratings in an array.
Both kitParentheses
and efficiencyRatings
have a size of m
. Initially, the EfficiencyScore of the sequence s
is 0. The user can use any number of unused parentheses from the kit to create the final sequence, as long as the final sequence remains balanced.
Objective:
Determine the maximum possible EfficiencyScore for the resulting balanced sequence.
Sample Case 0
Input:
s
="()"
kitParentheses
="(())"
efficiencyRatings
=[4, 2, -3, -3]
Explanation:
- The initial sequence is already balanced.
- The user can add parentheses from the kit to maximize the total EfficiencyScore:
- Use the 0th indexed parentheses (
4
) and add it to the start of the sequence. - Use the 2nd indexed parentheses (
-3
) and add it to the end of the sequence.
- Use the 0th indexed parentheses (
- The resulting sequence becomes:
"(0)"
(still balanced).
4 + (-3) = 1
There are no other combinations of parentheses that yield a higher EfficiencyScore. Therefore, the answer is 1.
Output:
1
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.