FastPrepFastPrep
Problem Brief

Score Tokens on a Board

INTERNNEW GRADOA

There is a board with N cells (numbered from 0 to N-1) arranged in a row. The board is described by an array points and a string tokens, both of length N. The k-th letter of the string tokens is either 'T' or 'E', indicating whether the k-th cell contains a token or is empty.

If the k-th cell contains a token, we score the number of points equal to points[k]. Additionally, we score another point for every pair of adjacent tokens. What is the total number of points we score?

that, given an array of integers points and a string tokens, both of length N, returns the total number of points scored.

🐳 Can’t thank Rachel enough, as always 🧡

1Example 1

Input
points = [3, 4, 5, 2, 3], tokens = "TEETT"
Output
9
Explanation

Cells 0, 3 and 4 contain tokens. The sum of points in these cells is 8. Also, there is one pair of adjacent cells with tokens, which results in 1 extra point. The function should return 9.

2Example 2

Input
points = [3, 2, 1, 2, 2], tokens = "ETTTE"
Output
7
Explanation

Cells 1, 2 and 3 contain tokens. The sum of points in these cells is 5. Also, there are two pairs of adjacent cells with tokens, which results in 2 extra points. The function should return 7.

3Example 3

Input
points = [2, 2, 2, 2], tokens = "TTTT"
Output
11
Explanation

All cells contain tokens. The function should return 11.

Constraints

Limits and guarantees your solution can rely on.

  • Array points and string tokens are of the same length N;
  • N is an integer within the range [1..100];
  • Each element of array points is an integer within the range [1..1,000];
  • String tokens consists only of the characters 'E' and/or 'T'.
public int googleScoreToken(int[] points, String tokens) {
  // write your code here
}
Input

points

[3, 4, 5, 2, 3]

tokens

"TEETT"

Output

9

Sign in to submit your solution.