Will you asked to give another solution to a problem that is no more optimized than your current one?

Chase / Eng ghosted!
Sep 14, 2018 3 Comments

ie, a tree-related problem has 3 ways to solve, time complexity is same across. Space complexity is such that recursive dfs is worst due to stackoverflow risk, followed by iterative DFS and then iterative BFS.

1) iterative DFS
2) iterative BFS
3) recursive dfs

Now, if you already gave a working iterative DFS solution, how likely is the interviewer to ask you to 'solve it another way', even though any other way is not any more efficient?

I can see if you give a recursive dfs solution, you may be asked 'can you do it iteratively to eliminate stack overflow risk', but vice versa?

comments

Want to comment? LOG IN or SIGN UP
TOP 3 Comments
  • lmao we're not mind readers. Maybe the interviewer will ask that, maybe they won't because they want to move on to another question who tf knows? Just be able to cover all your bases while you're studying, but trying to strategize like this is stupid.
    Sep 14, 2018 0
  • Microsoft TC_GTFO
    Unlikely, but not impossible. you will spend most of that 35 mins working on logic and coding and if you finish early then you will get another question.
    Sep 14, 2018 0
  • New / Eng rainbowcat
    Maybe you thought there's no other way, but in fact the problem could be solved using DP and interviewer want you to figure it out.
    Sep 14, 2018 0