Problem Statement: Magical Number Pairs
In the mystical realm of Numeria, numbers hold secrets waiting to be uncovered. Among the enchanted integers, there are special pairs that nearly mirror each other except for a single trait. You have been provided with an array of these magical numbers, numbers
. Your task is to discover how many unique pairs (i, j)
exist such that 0 ≤ i < j < numbers.length
, where the numbers are identical in length but differ by exactly one digit.
Example
For numbers = [1, 151, 241, 1, 9, 22, 351]
, the output should be:
solution(numbers) = 3
numbers[0] = 1
has a single-digit difference withnumbers[4] = 9
.numbers[1] = 151
differs fromnumbers[6] = 351
solely in the first digit.numbers[3] = 1
also differs fromnumbers[4] = 9
in their single shared digit.
Observe that the identical numbers[0] = 1
and numbers[3] = 1
do not count as a pair since they are exactly the same.
Input/Output
- Execution time limit: 4 seconds (Python 3)
- Memory limit: 1 GB
- Input:
array.integer numbers
This array comprises positive integers of mystical significance.
Constraints:
1 ≤ numbers.length ≤ 10^4
Problem Statement: Simulating Water Flow
Civil engineers are simulating rainfall on a digital elevation model to study water flow. You are given:
- A 2D array of integers
heights
, representing terrain heights. - Two integers,
startRow
andstartCol
, indicating the water's starting point.
Rules for Water Flow:
- Water flows to adjacent cells (up, down, left, right) if the adjacent cell's height is less than or equal to the current cell's height.
- The flow stops when no adjacent cell has a lower or equal height.
Output:
Return a 2D array of integers where each cell contains the time step when it becomes wet, starting at 0
for the initial cell.
- If a cell remains dry, its value should be
-1
. - The dimensions of the output array must match those of the input
heights
.
Notes:
- You are not expected to provide the most optimal solution, but the time complexity should be no worse than O(heights.length2⋅heights[0].length2)O(\text{heights.length}^2 \cdot \text{heights}[0].\text{length}^2), which will fit within the execution time limit.
Example:
Input:
heights =
[
[3, 2, 1],
[6, 5, 4],
[9, 8, 7]
]
startRow = 1
, startCol = 1
Output:
solution(heights, startRow, startCol) =
[
[-1, 1, 2],
[-1, 0, 1],
[-1, -1, -1]
]
Problem Statement: Simulating Water Flow
Rules for Water Flow:
- Water flows to adjacent cells (up, down, left, right) if the adjacent cell's height is less than or equal to the current cell's height.
- The flow stops when no adjacent cell has a lower or equal height.
Input:
- heights: A 2D array of integers representing terrain heights.
- startRow, startCol: Integers representing the water's starting point.
Output
- A 2D array of integers where each cell contains the time step when it becomes wet, starting at
0
for the initial cell. - If a cell remains dry, its value should be
-1
. - The dimensions of the output array must match those of the input
heights
.
Notes:
You are not required to provide the most optimal solution, but a solution with a time complexity not worse than
O(heights.length2⋅heights[0].length2)O(\text{heights.length}^2 \cdot \text{heights}[0].\text{length}^2)
will fit within the execution time limit.
Example:
Input:
heights =
[
[3, 2, 1],
[6, 5, 4],
[9, 8, 7]
]
startRow = 1
, startCol = 1
Output:
solution(heights, startRow, startCol) =
[
[-1, 1, 2],
[-1, 0, 1],
[-1, -1, -1]
]
我们长期稳定承接各大科技公司如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.