-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolve.py
executable file
·44 lines (34 loc) · 1.64 KB
/
solve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Instructions:
- Implement the function `path_exists` below.
- Save this file as `{first_name}_{last_name}_solve.py`.
Constraints:
- Your solution will be run in a Python2.7 environment.
- Only python standard library imports can be used and they must be imported within `path_exists`.
- The function signature of `path_exists` cannot be modified.
- Additional functions can be included, but must be defined within `path_exists`.
- There will be two sets of input, small and large, each with different time limits.
"""
def path_exists(grid, queries):
"""
Determines whether for every start=(i1, j1) -> end=(i2, j2) query in `queries`,
there exists a path in `grid` from start to end.
The rules for a path are as follows:
- A path consists of only up-down-left-right segments (no diagonals).
- A path must consist of the same values. i.e. if grid[i1][j1] == 1, the path is comprised of only 1's.
Examples:
grid (visual only)
1 0 0
1 1 0
0 1 1
start end answer
(0, 0) -> (2, 2) True
(2, 0) -> (0, 2) False
:param grid: The grid on which `queries` are asked.
:type grid: list[list[int]], values can only be [0, 1].
:param queries: A set of queries for `grid`. Queries will be non-trivial.
:type queries: Iterable, contains elements of type tuple[tuple[int, int]].
:return: The result for each query, whether a path exists from start -> end.
:rtype: list[bool]
"""
raise NotImplementedError