华人公司Weride对北美的小伙伴们是个不错的机会,如果您是明年的NG,不妨试试。
Question 1
In many real-world applications, the problem of finding a pair of closest points arises. In the real world, data is usually distributed randomly. Given n
points on a plane, randomly generated with uniform distribution, find the squared shortest distance between pairs of these points.
Example
There are 3 points with x-coordinates x = [0, 1, 2]
and y-coordinates y = [0, 1, 4]
. The points have the coordinates:
(0, 0)
(1, 1)
(2, 4)
The closest points are (0, 0)
and (1, 1)
, and their squared shortest distance is:
(1 - 0)^2 + (1 - 0)^2 = 2
Function Description
Complete the function closestSquaredDistance
in the editor below.
closestSquaredDistance
has the following parameter(s):
int x[n]
: An array where eachx[i]
denotes the x-coordinate of the i-th point.int y[n]
: An array where eachy[i]
denotes the y-coordinate of the i-th point.
Returns:
long
: A long integer that denotes the squared shortest distance between the pairs of points.
Question 2
Given an array of strings, each of the same length, and a target string, construct the target string using characters from the strings in the given array such that the indices of the characters, in the order in which they are used, form a strictly increasing sequence. Here, the index of a character is the position at which it appears in the string. Note that it is acceptable to use multiple characters from the same string.
Objective
Determine the number of ways to construct the target string. One construction is different from another if:
- The sequences of indices they use are different, or
- The sequences are the same but there exists a character at some index that is chosen from a different string in these constructions.
Since the answer can be very large, return the value modulo 10^9 + 7
.
Example
Consider an example with n = 3
strings, each of length 3. Let the array of strings be:
words = ["adc", "aec", "efg"]
and the target string be:
target = "ac"
There are 4 ways to reach the target:
- Select the 1st character of
"adc"
and the 3rd character of"adc"
. - Select the 1st character of
"adc"
and the 3rd character of"aec"
. - Select the 1st character of
"aec"
and the 3rd character of"adc"
. - Select the 1st character of
"aec"
and the 3rd character of"aec"
.
Function Description
Complete the function numWays
in the editor below. It must return an integer, modulo 10^9 + 7
.
numWays
has the following parameter(s):
string words[n]
: An array of strings.string target
: The target string.
Constraints
- 1 ≤
n
≤ 1000 - 1 ≤ length of
words[i]
≤ 3000 - All strings in
words
are of equal length per test case. - The total length of all strings in
words
does not exceed 100000. - 1 ≤ length of
target
≤ length ofwords[i]
- All characters are lowercase English letters.
Question 3
There are employee_nodes
employees in a company, out of which there are k
special employees who have data networks and can share their mobile hotspots with other employees. There are employee_edges
connections already made between the employees, where the i-th
connection connects the employees employee_from[i]
and employee_to[i]
, such that either of the employees employee_from[i]
and employee_to[i]
can share a mobile hotspot.
Two employees x
and y
are connected if there is a path between them. All employees connected to a special employee x
will use the mobile hotspot of the special employee x
.
To restrict data usage:
- Previously, any employee was connected to at most one special employee.
- Now, as data consumption has increased, any employee can be connected to at most
max_connections
number of special employees.
Objective
Find the maximum number of edges that can be added to the graph such that:
- Any employee is connected to at most
max_connections
special employees. - The graph does not contain self-loops or multiple edges between nodes.
It is guaranteed that in the given graph, no two special employees are connected to each other.
Example
Input:
employee_nodes = 4
employee_edges = 1
k = 2
max_connections = 1
special_employees = [1, 3]
employee_from = [1]
employee_to = [2]
Explanation: Employees 1 and 3 are special, and max_connections = 1
, so they cannot be connected. Hence:
- Employee 4 can be connected to 1 and 2, making two total edges.
Output:2
Function Description
Complete the function getMaximumEdges
in the editor below.
getMaximumEdges
has the following parameters:
int employee_nodes
: The number of employees.int employee_from[employee_edges]
: The one end of the connection.int employee_to[employee_edges]
: The other end of the connection.int special_employees[k]
: The list of special employees.int max_connections
: The maximum number of special employees to which an employee can be connected.
Returns:
long
: The maximum number of edges that can be added to the graph such that any employee is connected to at mostmax_connections
special employees.
Constraints
- 1 ≤
employee_nodes
≤ 200,000 - 1 ≤
employee_edges
≤ 200,000 - 1 ≤
k
≤employee_nodes
- 1 ≤
max_connections
≤employee_nodes
我们长期稳定承接各大科技公司如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.