[Google] AMS OA 2025 Start – 9 Jan

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: 9988, 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.


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<int>& 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. Also, there is one pair of adjacent cells with tokens, which results in 1 extra point. The function should return 9.
  2. Assume that points = [8, 2, 1, 2, 2] and tokens = "ETETT".
    Cells 1, 3, and 4 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.
  3. Assume that points = [2, 2, 2, 2, 2] and tokens = "TTTTT".
    All cells contain tokens.
    The function should return 13.

Assume that:

  • points and tokens are of the same length N.
  • N is an integer within the range [1..100].
  • Each element of the array points is an integer within the range [1..1,000].
  • tokens consists only of the characters "E" and/or "T".

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 *