注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
Code Question 1
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.
A sequence is considered balanced if it has an equal number of opening '(' and closing ')' parentheses, with each opening parentheses properly matched with a closing one in the correct order (i.e., circular balance). For instance, sequences like ((),(), and (((())) are balanced, while sequences like ), ((), and (())( are not.
You are given an initial parentheses sequence represented by the string ss, 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 ss 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.Example
s="(("s=&quochanging their order.
Language Java 8
& Autocomplete Ready
- import java. 10.*:
14
15
16
class Result (
17
18
Hint: It can be proved that (a + b) % c = ((a % c) + (b % c)) % c where a, b,
and c are integers and % represents the modulo operation.
Function Description
Complete the function getMinErrors in the editor below.
19
20
- Complete the 'getMinErrors' function below.
- The function is expected to return an
21
getMinErrors has the following parameter(s):
string errorString: a string of characters 'O', '1', and 'T' int x: the number of errors generated for every occurrence of
subsequence 01
int y: Ithe number of errors generated for every occurrence of
subsequence 10
INTEGER. - The function accepts Following parameters:
- 1, STRING errorString
Returns
int: the minimum number of errors possible, modulo 10^9+7
Constraints
• 1 ≤ len(errorString) ≤ 10^5
• 0 ≤ x, y ≤ 10^5
• s consists only of characters 'O', 'T, and '!' |