Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def findJudge(self, n: int, trust: List[List[int]]) -> int:
if n == 1 and not trust: return 1
indegree = defaultdict(int) #[indegree,
outdegree = defaultdict(int) #outdegree

for i, j in trust:
indegree[j] += 1
outdegree[i] += 1

for _n in range(1, n+1):
if indegree[_n] == n-1 and outdegree[_n] == 0:
return _n
return -1

#TC V+E where V is no of people and E is number of relations
57 changes: 57 additions & 0 deletions Problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Solution:
def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool:
q = deque()
ROWS, COLS = len(maze), len(maze[0])

def isValidCell(curi, curj):
if not 0 <= curi < ROWS or not 0 <= curj < COLS:
return False
return True

seen = set()
q.append(start)

while q:
curi, curj = q.popleft()


if not isValidCell(curi, curj) or maze[curi][curj] == 1 or (curi, curj) in seen:
continue

seen.add((curi, curj))
#print(curi, curj)

#4 directions while loop right?
#left 0, -1
newi, newj = curi, curj
while isValidCell(newi, newj) and maze[newi][newj] != 1:
newj -= 1
newj+=1
if [newi, newj] == destination:return True
if (newi, newj) not in seen: q.append((newi, newj))

#right 0, 1
newi, newj = curi, curj
while isValidCell(newi, newj) and maze[newi][newj] != 1:
newj += 1
newj-=1
if [newi, newj] == destination:return True
if (newi, newj) not in seen: q.append((newi, newj))

#top -1, 0
newi, newj = curi, curj
while isValidCell(newi, newj) and maze[newi][newj] != 1:
newi -= 1
newi+=1
if [newi, newj] == destination:return True
if (newi, newj) not in seen: q.append((newi, newj))

#bottom 1, 0
newi, newj = curi, curj
while isValidCell(newi, newj) and maze[newi][newj] != 1:
newi += 1
newi-=1
if [newi, newj] == destination:return True
if (newi, newj) not in seen: q.append((newi, newj))

return False