Detecting Cycles in 2D Grid with DFS

Day 116 Solved 1559. Detect Cycles in 2D Grid 🔁 Today’s problem was a great exercise in DFS + cycle detection in grids. 🔍 Key learnings: How to detect cycles while avoiding revisiting the immediate parent node Using DFS with direction vectors efficiently Tracking visited cells smartly to prevent false positives 💡 The tricky part was ensuring we don’t count the previous cell as a cycle — small detail, big impact. ⏱️ Performance: Runtime: 27 ms Memory: 64.79 MB Every day, a little sharper. On to Day 117 💪 #DSA #CodingJourney #100DaysOfCode #LeetCode #DFS #ProblemSolving

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories