Sponsored
Use these hints if you're stuck. Try solving on your own first.
Keep track of the parent (previous position) to avoid considering an invalid path.
Use DFS or BFS and keep track of visited cells to see if there is a cycle.
Solve with full IDE support and test cases