We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Red Knight's Shortest Path
Red Knight's Shortest Path
Sort by
recency
|
54 Discussions
|
Please Login in order to post a comment
def is_valid(i, j, n): """ Check if the cell (i, j) is within the grid boundaries """ return 0 <= i < n and 0 <= j < n
def get_neighbours(loc, n): """ Get valid neighboring cells and their corresponding move names """ i, j = loc[0], loc[1] name = ['UL', 'UR', 'R', 'LR', 'LL', 'L'] dr = [-2, -2, 0, 2, 2, 0] cr = [-1, 1, 2, 1, -1, -2] res = []
def printShortestPath(n, i_start, j_start, i_end, j_end): """ Print the shortest path from (i_start, j_start) to (i_end, j_end) """
Reading input and calling the function
if name == 'main': import os import sys input = sys.stdin.read data = list(map(int, input().strip().split()))
Really liked the problem, basically used everything there are with bfs.
Python solution:
C++ BFS solution
Easily readible python solution
C++ BFS-tree(more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )