- // Suppose we have some input data describing a graph of relationships between parents and children over multiple generations. The data is formatted as a list of (parent, child) pairs, where each individual is assigned a unique integer identifier.
- // For example, in this diagram, 6 and 8 have a common ancestor of 4.
- // 14 13
- // | |
- // 1 2 4 12
- // \ / / | \ /
- // 3 5 8 9
- // \ / \ \
- // 6 7 11
- // parentChildPairs1 = [
- // (1, 3), (2, 3), (3, 6), (5, 6), (5, 7), (4, 5),
- // (4, 8), (4, 9), (9, 11), (14, 4), (13, 12), (12, 9)
- // ]
- // Write a function that takes the graph, as well as two of the individuals in our dataset, as its inputs and returns true if and only if they share at least one ancestor.
复制代码
/*
Imagine we have an image. We'll represent this image as a simple 2D array where every pixel is a 1 or a 0.
The image you get is known to have potentially many distinct rectangles of 0s on a background of 1's. Write a function that takes in the image and returns the coordinates of all the 0 rectangles -- top-left and bottom-right; or [1, 1, 1, 1, 1],
]
findRectangles(image4) =>
// (using top-left-row-column and bottom-right or top-left-x-y and width/height):
[
[[1,1],[3,3]],
]
n: number of rows in the input image
m: number of columns in the input image
*/
|