input: 
  from typing import List
  
  def solve_maze(n: int, m: int, grid: List[List[int]]) -> List[int]:
      """ Given a maze in a 2D grid represented by rows and columns (n, m), solve the maze and return the path of nodes from start (0, 0) to end (n-1, m-1).
      The grid is composed of 1s representing paths and 0s representing walls.
      >>> solve_maze(3, 3, [[1, 0, 1], [1, 1, 0], [0, 1, 1]])
      [5, 6, 7, 8]
      >>> solve_maze(2, 2, [[1, 1], [1, 1]])
      [3, 2]
      """
  
output:     
      directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
      queue = [(0, 0, [])]
      visited = set()
      while queue:
          x, y, path = queue.pop(0)
          if (x, y) == (n-1, m-1):
              return path + [x * m + y]
          if (x, y) in visited:
              continue
          visited.add((x, y))
          for dx, dy in directions:
              nx, ny = x + dx, y + dy
              if 0 <= nx < n and 0 <= ny < m and grid[nx][ny] == 1:
                  queue.append((nx, ny, path + [x * m + y]))
      return []
  