I took part in the leetcode biweekly competetion. One of the problem was
5073. Minimum Knight Moves
https://leetcode.com/contest/biweekly-contest-9/problems/minimum-knight-moves/
I thought it was a DP problem and should not be solved with graph algo(bfs or dfs (dfs not applicable here)).
Reason: I saw this an infinite grid and might lead to stack overflow if I use graph algorithm. Also, I am still getting used to DP. So since I was not comfortable with DP, so I didnt try. After the contest ended, I saw many people solved it using BFS.
There I was wrong, I could I have solved with BFS. I didnt even try beacuse I thought it will go in infinite loops.
According to my knowledge if input is too large then solving through graph algorithms leads to stack overflow / infinite loops. ( I am not sure this understanding is correct or not ?)
What am I missing here? I think there is some lack of my understanding ... Any suggestions/explainations?
Appreciated
Thanks!