input: 
  def solve_maze(maze_grid: List[List[int]]) -> List[int]:
      """The function solves a maze represented by a 2D grid where '1' indicates a path and '0' indicates a wall.
      The maze starts at the top-left corner (0, 0) and ends at the bottom-right corner (n-1, m-1).
      The function returns a list of values representing the path from start to end. Each value in the list indicates
      the number of moves from the start position to the respective position.
      If no path is found, an empty list is returned.
      
      >>> solve_maze([[1, 1, 1], [0, 1, 0], [1, 1, 1]])
      [0, 1, 2, 3, 4]
      >>> solve_maze([[1, 0, 1], [1, 0, 1], [1, 1, 1]])
      [0, 1, 2, 3, 4]
      >>> solve_maze([[1, 0, 0], [0, 0, 0], [1, 1, 1]])
      []
      """
  
output:     
      n = len(maze_grid)
      m = len(maze_grid[0])
      directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
      queue = [(0, 0, 0)]
      visited = [[False] * m for _ in range(n)]
      visited[0][0] = True
      path = {}
  
      while queue:
          x, y, dist = queue.pop(0)
          if (x, y) == (n-1, m-1):
              result = []
              while (x, y) != (0, 0):
                  result.append(path[(x, y)])
                  x, y = path[(x, y)]
              result.append(0)
              return result[::-1]
          
          for dx, dy in directions:
              nx, ny = x + dx, y + dy
              if 0 <= nx < n and 0 <= ny < m and maze_grid[nx][ny] == 1 and not visited[nx][ny]:
                  visited[nx][ny] = True
                  queue.append((nx, ny, dist + 1))
                  path[(nx, ny)] = (x, y)
      
      return []
  