1. Code Question 1
Your team at Amazon is developing a new algorithm for suggesting passwords when a user sets up a new account.
A string of lowercase English characters is said to be redundancy-free if each character occurs at most once in the string. In order to ensure minimum redundancy, the developers suggest a password that has the minimum number of redundancy-free segments it can be divided into.
Given a string, password
, find the minimum number of redundancy-free segments we can divide it into.
Example
The given password = "aabcdea"
.
aabcdea
a | abcde | a
The password can be partitioned into a minimum of 3 valid segments. Return 3.
Function Description
Complete the function getNumberRedundancyFree
in the editor below.
getNumberRedundancyFree
has the following parameter:
- string password: the given password
Returns
- int: the number of segments we can divide the string into
Constraints
- Length of
password
is between 1 and 100,000 inclusive. - All characters in
password
are lowercase English letters.
Sample Input For Custom Testing
STDIN FUNCTION
--------- --------
alabama password = "alabama"
Sample Output
4
Explanation
The minimum partitions are "al"
, "ab"
, "a"
, "ma"
.
Complete the function maxTransferRate
in the editor below.
maxTransferRate
has the following parameters:
- int throughput[n]: array of throughput provided by each server instance.
- int pipelineCount: the number of data pipelines that need to be connected.
Returns
- long: the maximum total
transferRate
from the unique connections of server pairs.
Constraints
- The size of
n
is between 1 and 200,000. - Each value in the array
throughput[i]
is between 1 and 200,000. - The
pipelineCount
is between 1 and the smaller value of 1 billion or n×nn \times n.
Sample Case 0
Input
STDIN FUNCTION
----- --------
5 throughput[] size n = 5
3 2 6 2 5 throughput = [3, 2, 6, 2, 5]
6 pipelineCount = 6
Output
62
Explanation
The six pairs of server instances with the highest sum of transferRate
are:
- [3, 3], [3, 5], [5, 3], [5, 5], [3, 1], [1, 3]. (Assuming 1-based indexing)
Thus total transferRate
will be calculated as:
- 12 (for [3, 3])
- 11 (for [3, 5]) + 11 (for [5, 3])
- 10 (for [5, 5]) + 9 (for [3, 1]) + 9 (for [3, 6])
Therefore, the total transferRate = 62
. Hence return 62 as the answer.
Sample Case 1
Input
STDIN FUNCTION
----- --------
4 throughput[] size n = 4
10 100 5 10 throughput = [10, 100, 5, 10]
4 pipelineCount = 4
Output
530
Explanation
The four pairs of server instances with the highest sum of transferRate
are:
- [2, 2], [2, 1], [2, 3], [1, 2] (Assuming 1-based indexing).
The total transferRate
is calculated as:
- 200 (for [2, 2])
- 200 (for [2, 1])
- 110 (for [2, 3])
- 110 (for [1, 2])
Thus, the total transferRate = 530
. Hence return 530 as the answer.
我们长期稳定承接各大科技公司如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.