Problem · Dynamic Programming

Calculate Efficiency Score

HardAmazonOA
See Amazon hiring insights

You are given an initial parentheses sequence represented by the string s, along with a Parentheses Perfection Kit containing different types of parentheses in the form of the string kitParentheses and their respective efficiency ratings in the efficiencyRatings array (both of size m). The EfficiencyScore of the original string s is initially 0. You can use any number of unused parentheses from the kit to create the final sequence, as long as the final sequence remains balanced.

The task is to determine the maximum possible EfficiencyScore that can be achieved for the resulting balanced sequence. Note: It is guaranteed that the sequence can be made balanced by adding zero or more parentheses from the kit.

Examples
01 · Example 1
s = ")(("
kitParentheses = ")(()))"
m = 6
efficiencyRatings = [3, 4, 2, -4, -1, -3]
return = TO-DO

TO-DO: Add explanation for the example here.

Constraints
  • 1 ≤ |s| < 2 * 105
  • 0 ≤ m < 2 * 105
  • -109 ≤ efficiencyRatings[i] ≤ 109
  • Both strings s and kitParentheses consist of opening and closing parentheses only
  • More Amazon problems
    drafts saved locally
    public int calculateEfficiencyScore(String s, String kitParentheses, int[] efficiencyRatings) {
      // write your code here
    }
    
    s")(("
    kitParentheses")(()))"
    m6
    efficiencyRatings[3, 4, 2, -4, -1, -3]
    expectedTO-DO
    sign in to submit