0

How to Discuss Edge Cases, Alternate Solutions, and The Approach in DSA Interviews?

Profile picture
Mid-Level Software Engineer at Taro Community6 days ago

I just finished the Master DSA Interview Course—fantastic material, thank you! I have three questions:

  1. In many problems, if we recognize the right pattern early, our initial code already handles most edge cases. So when a “Strong Yes” solution includes identifying 8+ edge cases, is the goal mainly to communicate to the interviewer that we’ve considered those scenarios (and confirm our code handles them), rather than necessarily rewriting the code to cover each one?
  2. Sometimes, a non–strictly worse alternate solution may not exist for a given problem. In those cases, are we expected to justify why no such alternate solution is possible? Or is it uncommon for interviewers to press on that point? I recall doing these types of proofs in university DSA courses, but I’m curious how often that level of justification is actually part of an interview setting.
  3. Alex emphasizes the importance of discussing your approach before jumping into code. How detailed should that discussion be? I sometimes find it difficult to clearly articulate a strategy when I haven’t seen the problem before. I might recognize patterns and have a general sense of how to attack it, but summarizing that strategy clearly—while still working through it mentally and continuing to talk—can be challenging. Any advice on how to strike the right balance between clarity and real-time problem solving?
36
3

Discussion

(3 comments)
  • 2
    Profile picture
    Helpful Tarodactyl
    Taro Community
    4 days ago

    I strongly agree with Alex/Rahul. A few thoughts I would like to add:

    • Depends on interviewer, but most would ask you to verbally describe edge case scenarios, rather than code.
    • Really like Alex's point about justifying the nonexistence of an alternate solution. For the explanation, it might be a good idea to refer to the idea of Best Conceivable Runtime (BCR).

      For an in-depth example about BCR, refer to this article https://medium.com/@iamsiddharths/maxing-out-your-code-unleashing-the-power-of-best-conceivable-runtime-bcr-fe282c2953c9
    • It would depend on the interview time constraint and the nature of the specific question. For example, if I were to encounter an implementation heavy question such as LRU cache, I would explain the high level approach more briefly so that I have sufficient time to code out everything.
  • 1
    Profile picture
    Tech Lead @ Robinhood, Meta, Course Hero
    5 days ago

    Glad you liked the course! As a heads up, a lot of these angles will be prompted of you in top-level interviews - You don't need to bring them up proactively usually. As you mentioned, it's possible that there is no alternate solution.

    ...is the goal mainly to communicate to the interviewer that we’ve considered those scenarios (and confirm our code handles them), rather than necessarily rewriting the code to cover each one?

    The goal of the interviewer is mainly to make sure that you're aware of the edge cases and that you know how to modify the code to handle them. Making you write code to handle all of them would take too much time, and the interviewer would lose signal.

    In those cases, are we expected to justify why no such alternate solution is possible?

    You don't need a full-on academic proof, but you will need to justify why an alternate solution doesn't exist. Common examples are pointing out that a problem that intrinsically requires sorting can't be better than O(n log n) or how a problem that requires at least 1 duplication or mapping/mirror of the source data can't be better than O(n) space.

    How detailed should that discussion be?

    Again, you need to play it by ear. Start off with a high-level description that's maybe a paragraph if your verbal speech was converted to text. If the interviewer isn't sold on your approach, they will press you for more details.

  • 1
    Profile picture
    Tech Lead/Manager at Meta, Pinterest, Kosei
    4 days ago

    How detailed should that discussion be?

    I agree with Alex. You need to develop the skill of reading the interviewer's tone and body language. This is easier to do in-person compared to a virtual interview.

    There are often 2 or even 3 questions opened in a single DSA interview. So if you are extremely thorough and spend 10 min clarifying edge cases for the first problem, you are robbing yourself of valuable time for subsequent questions.

    You should check with the interviewer occasionally by asking "how does that sound?" before diving into something new. That way you can quickly get to the coding if it's intended to be an easy problem