Taro Logo
8

How do you find edge cases in DSA problems for FAANG?

Profile picture
Senior Software Engineer at Taro Community8 months ago

How do I find edge cases in DSA problems?

Are there some common edge cases that everybody knows about?

Is there some sort of method or procedure to find those edge cases?

896
2

Discussion

(2 comments)
  • 9
    Profile picture
    Tech Lead @ Robinhood, Meta, Course Hero
    8 months ago

    Make things weird and try to break stuff.

    This really doesn't have to be taught - It's more about bringing out your inner survival instinct. Humans have evolved over millions of years to be careful:

    • Maybe these brightly colored berries I found are poisonous and I shouldn't eat them?
    • Maybe this dark cave I can't see into has a pack of hungry wolves so I shouldn't go in?
    • Maybe I should start this cooking fire further away from my hut so it doesn't accidentally catch on fire?

    Tap into that worry and apply it to your code. Leverage your fear to conquer your fear. This is where I've seen mediocre engineers fail time and time again. They are afraid to face their fear of their code being bad. They only think about the happy flow. They only run the happy flow. That works in the beginning, but the second anybody tries something weird against their code, the happiness is smashed to pieces.

    When you get a DSA problem or any problem really (it doesn't have to be FAANG or DSA), take the happy flow and mangle it as much as possible. In DSA, the interviewer will generally give you sample, neatly packaged test cases to illustrate the problem - Use those as a basis to turn everything on its head.

    The edge cases will vary for different problems (these companies are trying to gauge your on-the-spot creativity), so you naturally can't study your way out of this. But to help you out, here's some common edge cases:

    • Things are null or empty
    • Things are very big or very small
    • Everything is the same
    • Everything is different
    • Function parameters directly contradict each other

    Check these out for more inspiration:

    For an extremely in-depth guide on how to become a better coder in general (not just DSA), check this out: "How to Learn/Practice Clean Code, particularly by oneself?"

  • 3
    Profile picture
    Tech Lead/Manager at Meta, Pinterest, Kosei
    8 months ago

    I'd also embed this into your interview practice. Edbert talks about "Not Fixing Your Own Mistakes" in his talk about common mistakes among interviewees.

    Alex's list of common edge cases is great: start there and add other edge cases as you find them!