I recently had an interview where I had to solve a problem with a graph algorithm (find a path where starting node could be any and the path has a pattern). In that graph O(V) = O(E).
I started with all the possible nodes and did a dfs for each of them and wrote my code. As I reset my visited status at every dfs and started with a new node I came up with an O(n^2) algorithm.
As soon as the interview ended I realised that I could have designed a O(n) algorithm just starting a bfs with all the nodes together and search for the pattern (I was only reqired to find if the pattern exists). In that case that would be a O(n) algorithm. I do not remember doing any with starting with all nodes and I tried to reach just a solution first not an efficient one, it is an important pattern to practice as well. Graph bfs where to we start with all nodes and look for one destination or one path only. Is there many leetcode problems like that?