Skip to content

Instantly share code, notes, and snippets.

View AdelBeit's full-sized avatar

Adele Beitvashahi AdelBeit

View GitHub Profile
@AdelBeit
AdelBeit / Castle-on-the-grid.py
Last active December 28, 2021 03:10
hackerrank castle on the grid problem | shorted path with BFS
import queue
def minimumMoves(grid, startX, startY, goalX, goalY):
# bfs with visited list and parent list
# backtrack using parent links once bfs finds path to goal
visited = [[0 for col in row] for row in grid]
parentGrid = [[0 for col in row] for row in grid]
neighborQueue = queue.Queue()
neighborQueue.put((startY, startX))
turns = 0
HEIGHT, WIDTH = len(grid), len(grid[0])
#
# @lc app=leetcode id=733 lang=python3
#
# [733] Flood Fill
#
from collections import deque
from typing import List
# @lc code=start
#
# @lc app=leetcode id=695 lang=python3
#
# [695] Max Area of Island
#
from typing import List
from collections import deque
# @lc code=start
#
# @lc app=leetcode id=567 lang=python3
#
# [567] Permutation in String
#
from collections import Counter
# @lc code=start
class Solution:
#
# @lc app=leetcode id=617 lang=python3
#
# [617] Merge Two Binary Trees
#
# @lc code=start
# Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
#
# @lc app=leetcode id=994 lang=python3
#
# [994] Rotting Oranges
#
from typing import List
# @lc code=start
class Solution:
#
# @lc app=leetcode id=542 lang=python3
#
# [542] 01 Matrix
#
from typing import List
from collections import deque
# @lc code=start
#
# @lc app=leetcode id=21 lang=python3
#
# [21] Merge Two Sorted Lists
#
from typing import Optional
# @lc code=start
# Definition for singly-linked list.
#
# @lc app=leetcode id=206 lang=python3
#
# [206] Reverse Linked List
#
from typing import Optional
# @lc code=start
#
# @lc app=leetcode id=46 lang=python3
#
# [46] Permutations
#
from typing import List
# @lc code=start