Implement a Python function named shortest_path_with_obstacles(mat, k) that calculates the shortest path from the top-left corner to the bottom-right corner of a grid, taking into account obstacles. The grid is represented by a 2D list mat, where each cell can either be 0 (no obstacle) or 1 (obstacle). The function should allow for the removal of at most k obstacles. If a path exists, the function should return the number of steps in the shortest path. If no path exists, return -1.
Input/Output Requirements
Input:
mat: A list of lists (2D array) where mat[i][j] is either 0 (no obstacle) or 1 (obstacle).
k: An integer representing the maximum number of obstacles that can be removed.
Output:
An integer representing the minimum number of steps required to get from the top-left corner to the bottom-right corner, or -1 if it's not possible to reach the bottom-right corner with the given constraints.
Implementation
The implementation should be written in a single file named /app/solution.py.
The solution should handle edge cases, including:
An empty grid or grids without a valid path.
The case where k is sufficient to remove all obstacles along a potential path.
Ensure that the function efficiently explores potential paths using a breadth-first search approach, taking into consideration the allowed number of obstacle removals.
Example
python
# Example input
mat = [[0,0,0],[1,1,0],[0,0,0]]
k = 1
# Example output
result = shortest_path_with_obstacles(mat, k) # Expected output: 4