Amazon oa record 2025/07/20 – OA代写 – OA 代做 – OA help

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 1Skill 2Skill Sum
235
246
257
347
358
459

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 employees
  • int min_skill: the minimum total skill
  • int 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 01
  • int 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 NumberPossible StringCount of 01Count of 10Errors
100011117117
200011119018
300110117220
400110118016
501010116321
601011117117
701110115319
801111115010

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.

Leave a Reply

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