Tech IndustryJul 11, 2018

DP vs DFS

All, I see that some of the leetcode Medium/Hard problems are solved though DP and DFS. And the complexity of those apprchmdis still same. During the interview, Can we solve the problems using any of the approaches? Or it all depends on the interviewers.

Amazon dQkI67 Jul 11, 2018

Why use blind if you're going to sign off with your name?

Perficient AimFB OP Jul 11, 2018

Removed.

Amazon odVN70 Jul 11, 2018

Discuss both solutions and choose one to implement. If you really see no difference, go with the one you can more quickly write out without making mistakes

Microsoft fiana Jul 11, 2018

Usually DFS & backtracking based approaches have higher(think exponential) time complexities than DP. But if for a certain problem, they have the same complexity & you can prove this to the interviewer either should be fine.

Tesla LEETCODER Jul 11, 2018

If you are able to come up with both. Explain both to the interviewer. Some interviewers want to only see DP implementation. Some go so far as to say I only want bottom up approach. Sad but true.