I believe because that's O(26) which is constant time, it's a non-dominant term and can be ignored as it won't have any effect on the run-time as the problem input grows.
@@zhuolunzhou6074 I felt werid when he typed queue.size() and was wondering the size would change along with we offer the new word, thanks for pointing out!
Great video, thanks! But can you please explain why did you decide to go with BFS instead of DFS ? Can this be solved using DFS ? Also, can you please explain the time and space complexity in bit more detail.
Thank you, Nayak. In this problem, it's necessary to use BFS because it finds the length of the shortest path. DFS will not work for this problem because it will not necessarily find the length of the shortest path. The time complexity is O(L * N), where L is the length of each word and N is the number of words.
so you dont repeat the same word again. for ex: when you transform from DOG -> COG, you don't want to go from COG -> DOG again. I can expand on that if you want. =)
"lost" "cost" ["most","fist","lost","cost","fish"] Why does this test case expect output as 2 in leetcode? It should be 1 m assuming. Also, the code in the video gives 1 for this TC.
@K M when you reverse outer for loop you get expected output as 2 , but when i start i=0 in for loop then i get 1 , i also can't undeerstand y it's showing 2