KnightL on a Chessboard

Sort by

recency

|

126 Discussions

|

  • + 0 comments

    I can't help but feel like there's some mathematical way to figure this out without doing BFS, but I'm not quite able to get there.

  • + 0 comments

    Promotional merchandise for "KnightL on a Chessboard" can bring the classic strategy of chess to life. Custom chess sets featuring your brand’s logo or personalized pieces add a touch of sophistication. Branded chessboards, stylish keychains shaped like knights, or limited-edition chess piece stress balls can make thoughtful giveaways. Engage enthusiasts with these elegant items, perfect for corporate events or promotions that highlight strategy, skill, and timeless appeal.

  • + 0 comments

    The Knight's unique movement in chess, leaping in an "L" shape, allows it to control both near and distant squares, making it a versatile piece on the board; you can read more about the fascinating strategies involving the Knight at https://awomansjourney.com.

  • + 0 comments
    def knightlOnAChessboard(n):
        def bfs(n, a, b):
            directions = [(a, b), (a, -b), (-a, b), (-a, -b),
                          (b, a), (b, -a), (-b, a), (-b, -a)]
            queue = deque([(0, 0, 0)])
            visited = set([(0, 0)])
            
            while queue:
                x, y, dist = queue.popleft()
                if x == n-1 and y == n-1:
                    return dist
                
                for dx, dy in directions:
                    nx, ny = x + dx, y + dy
                    if 0 <= nx < n and 0 <= ny < n and (nx, ny) not in visited:
                        visited.add((nx, ny))
                        queue.append((nx, ny, dist + 1))
            
            return -1
    
        result = []
        for i in range(1, n):
            row = []
            for j in range(1, n):
                row.append(bfs(n, i, j))
            result.append(row)
        
        return result
    
  • + 0 comments

    C++ BFS approach (https://github.com/IhorVodko/Hackerrank_solutions/blob/master/Algorithms/knightLOnAChessboard.cpp, feel free to give a star :) )