**TSMC IT Hiring Test (General Guidelines)**

- This is an online coding test. We recommend you try the sample test or check the FAQ for a couple of minutes before taking the main test. Ensure you understand how to use the environment, such as viewing questions, selecting programming languages, checking & submitting your code.
- Photo taking is required to ensure your participation in the test. Therefore, please turn on the webcam before you start the test. Please read the privacy policy carefully before you begin.
- Since there are some conflicts between the system answering area and the Chinese input method, be careful not to accidentally type Chinese and switch to the English input method before answering.
- You can choose any of the supported programming languages (they are listed below) to complete the test.
- It is forbidden to discuss topics with others during the exam. You can search for the relevant descriptions and documentation of the programming language on the Internet, but the system will detect whether the program is copied or pasted.
- Please do not discuss or leak any contents about this test to others.
- This is a timed test. The time limit is 90 minutes, and there are 3 questions. We recommend taking an overview of all the questions before writing any code.
- Implement the required functions. Main function or headers are often provided, and you do not need to implement them.
- If a complete program is required, read the question carefully. All inputs are from STDIN, and outputs go to STDOUT. If you are writing Java, please use
`Solution`

as the class name. - Some test cases for each question are hidden. Make sure your program can process different scenarios (including edge cases) to get higher scores. Hard-coding test cases will not result in any scores.

**1. Question 1**

A warehouse manager needs to create a shipment to fill a truck. All of the products in the warehouse are in boxes of the same size. Each product is packed in some number of units per box. Given the number of boxes the truck can hold, determine the **maximum number of units** of any mix of products that can be shipped.

Example:`boxes = [1, 2, 3]`

`unitsPerBox = [3, 2, 1]`

`truckSize = 3`

The maximum number of units that can be shipped is `3 + 2 + 2 = 7`

units.

(Visual representation of product units in boxes)

**Function Description**

Complete the function `getMaxUnits`

in the editor below.

`getMaxUnits`

has the following parameters:

`long boxes[n]`

: a long integer array where`boxes[i]`

denotes the number of boxes product`i`

that are available`long unitsPerBox[n]`

: a long integer array where`unitsPerBox[i]`

denotes the number of units of product`i`

that are packed in each box of size`boxes[i]`

`long truckSize`

: a long integer that denotes the number of boxes the truck can carry

**Returns**:

`long`

: a long integer that denotes the maximum units that can be carried by the truck

**Constraints**:

`1 <= |boxes| <= 10^5`

`|boxes| == |unitsPerBox|`

`1 <= boxes[i] <= 10^7`

`1 <= unitsPerBox[i] <= 10^5`

`1 <= truckSize <= 10^8`

**2. Question 2**

A simple cipher is built on the **alphabet wheel** which has uppercase English letters ['A'-'Z'] written on it:

Given an encrypted string consisting of English letters ['A'-'Z'] only, decrypt the string by replacing each character with the `k`

th character away on the wheel in the counter-clockwise direction. Counter-clockwise is the opposite direction in which the hands on a clock usually move. In the image, Z is 1 unit counter-clockwise from A.

**Example**

`encrypted = VTAOG`

`k = 2`

Looking back 2 from `V`

returns `T`

, from `T`

returns `R`

, and so on. The decrypted string is `TRYME`

.

**Function Description**

Complete the function `simpleCipher`

in the editor below.

`simpleCipher`

has the following parameter(s):

`string encrypted`

: the string to decrypt`int k`

: the position of the character to find

**Returns**:

`string`

: the decrypted string

**Constraints**

`1 <= |encrypted| <= 10^5`

`1 <= k <= 10^5`

`encrypted[i] ∈ ascii['A'-'Z']`

**3. Question 3**

A linear equation of two variables is defined as `a * x + b * y = z`

. For an array of integers `arr`

and some query value `z`

, the **minimum sum solution** is the minimum possible value of `a + b`

where `0 <= a`

, `0 <= b`

, and `a * arr[i] + b * arr[j] = z`

. It is possible that `i = j`

.

Given two arrays of integers `arr`

, and `query`

, and an integer `k`

, for each value in `query`

, replace `z`

in the linear equation with `query[x]`

and find the minimum sum solution. Return an `answer`

array where each `answer[x]`

is the answer to `query[x]`

. If the sum of `a + b <= k`

, `answer[x]`

is `a + b`

. Otherwise, it is `-1`

.

Example:

`n = 5`

`arr[n] = [1, 2, 3, 6, 67]`

`q = 5`

`query[q] = [1, 4, 30, 7, 88]`

`k = 5`

query | i | j | a | b | a + b | comments |
---|---|---|---|---|---|---|

1 | 0 | 0 | 1 | 0 | 1 | 1 * 1 + 0 * 1 = 1 |

4 | 1 | 1 | 1 | 1 | 2 | 1 * 2 + 1 * 2 = 4 |

30 | 3 | 3 | 5 | 0 | 5 | 5 * 6 + 0 * 5 = 30 |

7 | 0 | 3 | 1 | 1 | 2 | 1 * 1 + 1 * 6 = 7 |

88 | - | - | - | - | -1 | Not possible, report -1 |

Hence the answer is `[1, 2, 5, 2, -1]`

.

**Function Description**

Complete the function `getMinSum`

in the editor below.

`getMinSum`

has the following parameters:

`int arr[n]`

: the input array`int query[q]`

: the queries`int k`

: the maximum allowed sum of`a`

and`b`

我们长期稳定承接各大科技公司如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.