[google] swe summer intern OA

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?

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 scored.

Examples:

  1. Assume that points = [3, 4, 5, 2, 3] and tokens = "TEETT".
    • Cells 0, 3, and 4 contain tokens.
    • The sum of points in these cells is 8.
    • There is one pair of adjacent cells with tokens, which results in 1 extra point.
    • The function should return 9.
  2. Assume that points = [3, 2, 1, 2, 2] and tokens = "TETTE".
    • Cells 1, 2, and 3 contain tokens.
    • The sum of points in these cells is 5.
    • There are two pairs of adjacent cells with tokens, which results in 2 extra points.
    • The function should return 7.
  3. Assume that points = [2, 2, 2, 2, 2] and tokens = "TTTTT".
    • All cells contain tokens.
    • The function should return 11.

Consider all codes made of four digits (0-9). How many of them have a sum of digits equal to S? For example, for S = 4, there are 35 such codes in total. Some of them are 0022, 1003, 1111, 2020, 4000.

Write a function:

int solution(int S);

that, given an integer S, returns the number of four-digit codes whose sum of digits is equal to S.

Examples:

  1. For S = 35, the possible codes are: 9998, 9989, 9899, 8999. The function should return 4.
  2. For S = 4, the function should return 35.
  3. For S = 2, the function should return 10.

Assume that:

  • S is an integer within the range [0, 36].

In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.


我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *