Problem · Array

Game Points Calculation

EasyGoogleOA
See Google hiring insights

Write a function: int solution(vector &points, string &tokens);

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

Assume that:

  • array points and string tokens are of the same length N;
  • N is an integer within [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'.

Big props to Aura Man!

Examples
01 · Example 1
points = [4, 0, 2, 2]
tokens = "TEET"
return = 9

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

02 · Example 2
points = [3, 2, 1, 2, 2]
tokens = "TTTE"
return = 10
Cells 0, 1 and 2 contain tokens. The value of points in these cells is 8. Also, there are two pairs of adjacent cells with tokens, which results in 2 extra points. The function should return 10.
03 · Example 3
points = [2, 2, 2, 2]
tokens = "TTTT"
return = 11
All cells contain tokens. The function should return 11.
More Google problems
drafts saved locally
public googlePointsCalculation (int[] points, String tokens) {
  // write your code here
}
points[4, 0, 2, 2]
tokens"TEET"
expected9
sign in to submit