1. Code Question 1
A product manager at Amazon wants to choose a two-member team for a project.
There are n employees to choose from where the iᵗʰ employee has a skill, skill[i]. The project needs a total skill between min_skill and max_skill, both inclusive.
Given the array skill, and two integers min_skill and max_skill, find the number of pairs of employees whose sum of skills is between min_skill and max_skill, both inclusive.
Example
n = 4
skill = [2, 3, 4, 5]
min_skill = 5
max_skill = 7
Skill 1 | Skill 2 | Skill Sum |
---|---|---|
2 | 3 | 5 |
2 | 4 | 6 |
2 | 5 | 7 |
3 | 4 | 7 |
3 | 5 | 8 |
4 | 5 | 9 |
Thus there are 4 possible pairs of employees.
Function Description
Complete the function countValidTeams
in the editor below.
countValidTeams
takes the following arguments:
int skill[n]
: the skills of the employeesint min_skill
: the minimum total skillint max_skill
: the maximum total skill
Returns
long int
: the number of pairs of employees with the sum of skills in the given range
Constraints
- 1 ≤ n ≤ 10⁵
- 1 ≤ skill[i] ≤ n
- 0 ≤ min_skill ≤ max_skill ≤ 10⁹
Sample Input For Custom Testing
Sample Case 0
STDIN FUNCTION
3 → skill[] size n = 3
6
2
3 → skill[] = [6, 2, 3]
7 → min_skill = 7
10 → max_skill = 10
Sample Output
2
Explanation
The two valid pairs are (6, 2) and (6, 3), with sums 8 and 9 respectively.
Sample Case 1
STDIN FUNCTION
2 → skill[] size n = 2
100
100 → skill[] = [100, 100]
200 → min_skill = 200
200 → max_skill = 200
Sample Output
1
Explanation
Only one pair meets the total skill of 100 + 100 = 200.

2. Code Question 2
Amazon’s database doesn’t support very large numbers, and hence, numbers are stored as a string of binary characters, ‘0’ and ‘1’. Accidentally, a ‘!’ was entered in some positions, and it is unknown whether they should be ‘0’ or ‘1’.
The string of incorrect data consists of the characters ‘0’, ‘1’, and ‘!’, where ‘!’ represents an unknown character. The ‘!’ can be replaced with either ‘0’ or ‘1’. Due to some internal faults, errors are generated every time the characters ‘0’ and ‘1’ appear together as ‘01’ or ‘10’ in any subsequence of the string. It is observed that the number of errors a subsequence ‘01’ generates is x while a subsequence ‘10’ generates y errors.
Determine the minimum total errors generated. Since the answer can be very large, return it modulo 10⁹ + 7.
Example
errorString = "10!11"
x = 2
y = 3
- If the ‘!’ at index 3 is replaced with ‘0’, the string is "10011". The number of times the subsequence 01 occurs is 3 at indices (0, 2), (0, 4), and (3, 4). The number of times the subsequence 10 occurs is also 3, indices (0, 1), (0, 3) and (2, 3). The number of errors is 3 * x + 3 * y = 6 + 9 = 15.
- If the ‘!’ is replaced with ‘1’, the string is "10111". The subsequence 01 occurs 3 times and 10 occurs 1 time. The number of errors is 3 * x + y = 6 + 3 = 9.
The minimum number of errors is min(9, 15) modulo (10⁹ + 7) = 9
.
Note: A subsequence of a string is obtained by omitting zero or more characters from the original string without changing their order.
Hint: It can be proved that (a + b) % c = ((a % c) + (b % c)) % c where a, b, and c are integers and % represents the modulo operation.
Function Description
Complete the function getMinErrors
in the editor below.
getMinErrors
has the following parameter(s):
string errorString
: a string of characters '0', '1', and '!'int x
: the number of errors generated for every occurrence of subsequence 01int y
: the number of errors generated for every occurrence of subsequence 10
Returns
int
: the minimum number of errors possible, modulo 10⁹ + 7
Constraints
- 1 ≤ |errorString| ≤ 10⁵
- 0 ≤ x, y ≤ 10⁵
- s consists only of characters '0', '1', and '!'
Sample Input For Custom Testing
Sample Case 0
nginx复制编辑STDIN FUNCTION
0!1!11! → errorString = "0!1!11!"
2 → x = 2
3 → y = 3
Sample Output
10
Explanation
All possibilities are as follows:
Serial Number | Possible String | Count of 01 | Count of 10 | Errors |
---|---|---|---|---|
1 | 0001111 | 7 | 1 | 17 |
2 | 0001111 | 9 | 0 | 18 |
3 | 0011011 | 7 | 2 | 20 |
4 | 0011011 | 8 | 0 | 16 |
5 | 0101011 | 6 | 3 | 21 |
6 | 0101111 | 7 | 1 | 17 |
7 | 0111011 | 5 | 3 | 19 |
8 | 0111111 | 5 | 0 | 10 |
The minimum number of errors is 10. Thus, the answer is 10.
Sample Case 1
STDIN FUNCTION
!!!!!!! → errorString = "!!!!!!!"
23 → x = 23
47 → y = 47
Sample Output
0
Explanation
There is a tie for the best string generated, 000000 or 111111, with zero subsequences of 01 or 10.

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