"you are in charge of preparing a recently purchased lot" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "you are in charge of preparing a recently purchased lot" answered properly. Developers are finding an appropriate answer about you are in charge of preparing a recently purchased lot related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like you are in charge of preparing a recently purchased lot. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on you are in charge of preparing a recently purchased lot.
you are in charge of preparing a recently purchased lot
from collections import defaultdict
from collections import deque
def is_valid(i, j, m, n, matrix, visited):
if i >= 0 and j >= 0 \
and i < m and j < n \
and visited[i][j] is False \
and matrix[i][j] in (1, 9):
return True
return False
def remove_obstacle(matrix, m, n):
queue = deque()
i = 0
j = 0
queue.append((i, j, 0))
visited = [[False for _ in range(n)] for _ in range(m)]
distance_matrix = [[100 for _ in range(n)] for _ in range(m)]
visited[i][j] = True
while queue:
i, j, distance = queue.popleft()
distance_matrix[i][j] = distance
visited[i][j] = True
if matrix[i][j] == 9:
return distance
new_distance = distance + 1
if is_valid(i + 1, j, m, n, matrix, visited):
queue.append((i + 1, j, new_distance))
if is_valid(i - 1, j, m, n, matrix, visited):
queue.append((i - 1, j, new_distance))
if is_valid(i, j + 1, m, n, matrix, visited):
queue.append((i, j + 1, new_distance))
if is_valid(i, j - 1, m, n, matrix, visited):
queue.append((i, j - 1, new_distance))
return -1
if __name__ == '__main__':
m = 5
n = 4
l = [
[1, 1, 1, 1],
[0, 1, 1, 1],
[0, 1, 0, 1],
[1, 1, 9, 1],
[0, 0, 1, 1]
]
bfs = remove_obstacle(l, m, n)
assert bfs == 5
m = 3
n = 3
l = [
[1, 0, 0],
[1, 0, 0],
[1, 9, 1]
]
bfs = remove_obstacle(l, m, n)
assert bfs == 3
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on you are in charge of preparing a recently purchased lot can get a collection of related answers to their query. Programmers need to enter their query on you are in charge of preparing a recently purchased lot related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about you are in charge of preparing a recently purchased lot for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of you are in charge of preparing a recently purchased lot while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "you are in charge of preparing a recently purchased lot". Visit this developer's friendly online web community, CodeProZone, and get your queries like you are in charge of preparing a recently purchased lot resolved professionally and stay updated to the latest Whatever updates.