← 返回 bytedance 的题目列表Fill NxN Array Based on Coordinate Constraints
类型:online_judge
Given coordinate constraints for x-axis (0 to n-1) and y-axis (0 to n-1), fill an NxN array. The output should be an NxN 2D array satisfying that the order of elements in each row and each column reflects the given order constraints.
Input:
Integer n, denoting the size of the array.
2D list x_order, where each element is a tuple of two integers representing the x-axis order; the first coordinate should appear before the second.
2D list y_order, where each element is a tuple of two integers representing the y-axis order; the first coordinate should appear before the second.
Output:
An N*N 2D list in which each row and column follows the given order constraints.
Example:
Input:
n = 3
x_order = [(0, 1), (1, 2)]
y_order = [(0, 2), (2, 1)]
Output:
[[0, 0, 1],
[0, 1, 1],
[1, 1, 1]]
Constraints: 1 <= n <= 100. The total number of elements in x_order and y_order does not exceed 2*n.
Example
Input
3
0 1
1 2
0 2
2 1