input: from typing import List, Tuple
  
  class Maze:
      def __init__(self, n: int, m: int):
          self._n, self._m = n, m
          self._grid = [[0] * m for _ in range(n)]
      
      def solve_maze(self) -> List[int]:
          """Solve a maze represented by a binary grid and return the path length 
          from the start (top-left corner) to the end (bottom-right corner). 
          The grid is filled with ones (1s) representing the path and zeros (0s) 
          representing the walls.
          >>> maze = Maze(3, 3)
          >>> maze._grid = [[1, 0, 0], [1, 1, 0], [0, 1, 1]]
          >>> maze.solve_maze()
          [4]
          >>> maze = Maze(4, 4)
          >>> maze._grid = [[1, 0, 1, 1], [1, 0, 1, 0], [1, 1, 1, 0], [0, 0, 1, 1]]
          >>> maze.solve_maze()
          [5]
          """
          result, found = [], False
          start, end = (0, 0), (self._n-1, self._m-1)
  
          for i in range(self._n):
              for j in range(self._m):
                  if self._grid[i][j] == 1:
                      self._find_omega(i, j, 0, result, start, end, found)
                      return result
  
      def _find_omega(self, i: int, j: int, value: int, result: List[int], start: Tuple[int, int], end: Tuple[int, int], found: bool):
          rowNbr, colNbr = [-1, 0, 0, 1], [0, -1, 1, 0]
  
          if (i, j) == end:
              found = True
              result.append(value)
              return
  
          if found:
              return
  
          self._grid[i][j] = 0
          for k in range(4):
              if self._on_board(i + rowNbr[k], j + colNbr[k]):
                  self._find_omega(i + rowNbr[k], j + colNbr[k], value + 1, result, start, end, found)
  
      def _on_board(self, i: int, j: int) -> bool:
          return 0 <= i < self._n and 0 <= j < self._m and self._grid[i][j] == 1
output:     result, found = [], False
      start, end = (0, 0), (self._n-1, self._m-1)
  
      if self._grid[start[0]][start[1]] == 0 or self._grid[end[0]][end[1]] == 0:
          return []
  
      self._find_omega(start[0], start[1], 1, result, start, end, found)
      return result