Leetcode rant

New
ZZ23

New

ZZ23
Mar 8 19 Comments

I know, I know, but hear me out…

Many leetcode problems ask for changes to arrays or linked lists to be made in place. In the real world, I would strongly prefer to work with immutable arrays or linked lists and use pure functions to return the new desired result. I would object during code review if someone had the ability to do it this way and modified it in place instead.

In a coding round, you’re expected to write the code perfectly, think through all the edge cases, and “test” it manually by stepping through the code against some test cases to see if it works. In the real world, I would do TDD and simply rely on my test runner to tell me if my code works or not and where it fails. It’s less cognitive effort, less error-prone, and gets to the desired end result faster than trying to “test” it manually.

Why does leetcode require proficiency in these two things that are generally poor real world practices? Has anyone tried simply stating this in a coding interview? Did you get any credit for doing so?

I ask because I can solve most leetcode questions, and I can generally get to the optimal solution, but I can solve them SO much faster when I run the test suite and make the necessary changes based on the failing test cases, as opposed to trying to get it perfect before submitting. And I can do a lot more of them this way because it’s less mentally taxing. Which is what should be valued in the real world.

10+ YOE / $250k

comments

Want to comment? LOG IN or SIGN UP
TOP 19 Comments
  • Dropbox
    Dripbox💦

    Go to company page Dropbox

    Dripbox💦
    Because LC came into vogue and everyone blindly cargo culted it even though it’s a terrible proxy for real life performance, and here we are.

    It’s awful.
    Mar 8 2
  • Amazon
    nqQK13

    Go to company page Amazon

    nqQK13
    LC has been gamified by leetcode, algo expert, etc

    You’re expected to do it perfectly because some other kid has solved 500 LC problems and he solved it perfectly

    It’s not meant to test anything remotely related to the real world, it’s meant to filter out people that haven’t solved LC problems
    Mar 8 0
  • In place is helpful where you have memory constraints. For example compilers.

    You can rely on the test runner, but still have to come up with test cases.

    Writing error less code at once is a lot less time consuming than writing one line at once, compiling and debugging and writing another line

    Also, these leetcode tests don't only test your knowledge and coding skills but also how smart you are. Your cognitive skills.
    Taking 10 pointers simultaneously in mind and designing an approach is not a kids play.
    Mar 8 2
    • New
      ZZ23

      New

      ZZ23
      OP
      I would be happy to come up with a handful of test cases and explain why I believe they’re useful. Would likely take about a minute to create the cases and another couple of minutes to discuss and answer any questions.

      I also didn’t mean to suggest writing one line of code at a time. I meant writing a solution that’s 80% accurate and then letting the tests catch the 2-3 issues in order to focus efforts on fixing the issues rather than finding the issues. At least, that’s how I do TDD at my day job 🤷‍♂️.
      Mar 8
    • There are always better ways to do a job. That's what makes one a good engineer.

      I find significant improvement in productivity if I think of whole approach and test cases and then start write code.
      And trusting myself rather than relying on compiler. Sure may be alot more focused work but gets things done in lot less time for sure.
      Mar 8
  • I think the “not running code” thing is meant to help candidates focus on ideas and not spend 10 minutes in an interview debugging syntax errors. Also, it’s bonus points if you mention what kinds of edge cases you would test for. They just don’t want to sit around watching you write tests I guess.

    Immutable vs. mutable is hard because of all the code that has been written that’s mutable, plus garbage collection concerns.
    Mar 8 0
  • Google
    FMAU10

    Go to company page Google

    FMAU10
    Statelessness, immutability, small composible units with clean abstractions often comes at a cost of performance. For a lot of applications that is fine but for some (eg. hft, large scale backend systems) it is not so you have to make tradeoffs. For those jobs, majority of your time may be spent on thinking about those tradeoffs and actually coding it is the easy part.
    Mar 8 1
    • New
      ZZ23

      New

      ZZ23
      OP
      Very fair for large scale backends. FWIW, I’m a frontend dev.
      Mar 8