|
1 | 1 | # Instructions |
2 | 2 |
|
3 | | -Detect saddle points in a matrix. |
| 3 | +Your task is to find the potential trees where you could build your tree house. |
4 | 4 |
|
5 | | -So say you have a matrix like so: |
| 5 | +The data company provides the data as grids that show the heights of the trees. |
| 6 | +The rows of the grid represent the east-west direction, and the columns represent the north-south direction. |
6 | 7 |
|
7 | | -```text |
8 | | - 1 2 3 |
9 | | - |--------- |
10 | | -1 | 9 8 7 |
11 | | -2 | 5 3 2 <--- saddle point at column 1, row 2, with value 5 |
12 | | -3 | 6 6 7 |
13 | | -``` |
| 8 | +An acceptable tree will be the the largest in its row, while being the smallest in its column. |
14 | 9 |
|
15 | | -It has a saddle point at column 1, row 2. |
| 10 | +A grid might not have any good trees at all. |
| 11 | +Or it might have one, or even several. |
16 | 12 |
|
17 | | -It's called a "saddle point" because it is greater than or equal to |
18 | | -every element in its row and less than or equal to every element in |
19 | | -its column. |
| 13 | +Here is a grid that has exactly one candidate tree. |
20 | 14 |
|
21 | | -A matrix may have zero or more saddle points. |
| 15 | + 1 2 3 4 |
| 16 | + |----------- |
| 17 | +1 | 9 8 7 8 |
| 18 | +2 | 5 3 2 4 <--- potential tree house at row 2, column 1, for tree with height 5 |
| 19 | +3 | 6 6 7 1 |
22 | 20 |
|
23 | | -Your code should be able to provide the (possibly empty) list of all the |
24 | | -saddle points for any given matrix. |
| 21 | +- Row 2 has values 5, 3, and 1. The largest value is 5. |
| 22 | +- Column 1 has values 9, 5, and 6. The smallest value is 5. |
25 | 23 |
|
26 | | -The matrix can have a different number of rows and columns (Non square). |
27 | | - |
28 | | -Note that you may find other definitions of matrix saddle points online, |
29 | | -but the tests for this exercise follow the above unambiguous definition. |
| 24 | +So the point at `[2, 1]` (row: 2, column: 1) is a great spot for a tree house. |
0 commit comments