input: def findMinPath(grid, k):
      """
      Given an N x N grid (N >= 2) with each cell containing a unique value 
      from the range [1, N*N], and a positive integer k, find the lexicographically 
      smallest path of length k starting from any cell, moving to adjacent cells 
      (sharing an edge), without leaving the grid.
  
      A path of length k means visiting exactly k cells, which are not necessarily distinct.
      The path is considered smaller than another if the sequence of cell values 
      in the path is lexicographically smaller.
  
      Return the list of values in the cells of the minimum path.
  
      Examples:
  
          Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3
          Output: [1, 2, 1]
  
          Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1
          Output: [1]
      """
output:     
      from itertools import product
      from heapq import heappush, heappop
  
      def in_bounds(x, y, N):
          return 0 <= x < N and 0 <= y < N
  
      def findMinPath(grid, k):
          N = len(grid)
          directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
          min_heap = []
  
          for i, j in product(range(N), range(N)):
              heappush(min_heap, (grid[i][j], i, j, [grid[i][j]]))
  
          while min_heap:
              current_val, x, y, path = heappop(min_heap)
              if len(path) == k:
                  return path
              for dx, dy in directions:
                  nx, ny = x + dx, y + dy
                  if in_bounds(nx, ny, N):
                      new_path = path + [grid[nx][ny]]
                      heappush(min_heap, (grid[nx][ny], nx, ny, new_path))
  
          return []
  