BarclaysOA #2
Adjacent Tokens Scoring
EasyJudge-ready
Topics (AI-labelled)Simulation
A row has n cells; each cell has a value points[i], and its state is T if it holds a token or E if it is empty. Each T cell contributes its own value; each pair of adjacent T cells contributes an extra 1 point. Find the total score.
The rules, constraints, and two public examples correspond to the original Barclays problem.
Input
The first line contains n (1 ≤ n ≤ 100); the second line contains n integers points[i] (1 ≤ points[i] ≤ 1000); the third line contains a string of length n consisting only of E and T.
Output
Output a single integer, the answer.
Example 1
Input:
5
3 2 1 2 2
ETTTE
Output:
7
Example 2
Input:
4
2 2 2 2
TTTT
Output:
11
Example 3
Input:
5
3 4 5 2 3
TEETT
Output:
9
Example notes
In example 1 the tokens are in cells 0, 3, 4; the base score is 3+2+3=8, and the adjacent pair (3,4) adds 1, for a total of 9.
Editorial
Loading solution…