r/datascience • • Feb 15 '21

Job Search Please STOP asking Data Scientists about Leetcode questions meant for Software Engineers for job interviews

I've been working as a Data Scientist long enough to say that asking Leetcode questions for Data Scientists is completely disrespectful. This is both for both product and ML-based data scientists.

Something simple is fine, like hashmaps, two pointers, strings, some light algorithms etc. But graph theories, DFS with trees/dynamic programming has nothing to do with data analytics, ML fundamentals, statistical foundations, and data storytelling competence.

I really don't understand. When you have a wealth of ways to distinguish competent Data Scientists from juniors during interview pipeline (complicated SQL, pandas, data munging, visualization, ML training, building simulation code, etc.), why you'd rather choose questions like "how many moves do you need to get a Queen chess piece from this position to another on a chessboard" as a way of measuring how well a Data Scientist would perform analytics or ML training on the job. It really just feels like SWEs making fun of Data Scientists about how poor programmers we are.

Most companies don't pull crap like this, but for those who do, PLEASE STOP. Unless we received a BA or MA in computer science -- which majority if not most of us did not -- we won't be able to solve shit like this unless we cheat and look at answers directly on leetcode or geekforgeeks. And it's infuriating and embarrassing for us to sink to this kind of level to solve questions that aren't meant for us. I get that Data people need to know programming, but WE AREN'T SWEs, and DS is not SWE.

Edit: I'm getting a lot of replies saying that I suck at programming and I need to learn SWE fundamentals. I said over and over that I'm not against understanding foundations of SWE (hashmaps, runtime, pointers, optimized solutions vs brute force). These are important. But when you get into highly niched algorithm named after somebody where you need to do some complicated tricks or build a whole system that requires multiple functions, DFS-based dynamic programming, multiple inheritance methods all in 45 minutes that would unnerve even seasoned SWEs out of practice, that's when it becomes totally unreasonable, outside the realm of data science, and just disrespectful to what Data Scientists do on a daily basis. But that's the line I draw, and the overall question is: at what point do interview questions become unjustifiable and unrelated to the position at hand? I've spent years using pandas, scikit-learn, tableau, and complicated SQL for daily data tasks. Why is it that you can't test me on this stuff which occurs on day-to-day basis for majority of data scientists?

Edit Edit: Btw, shame on those of you just downvoting everything I'm saying without reading any of it (I can't even locate my own comments anymore). It's immature and completely ridiculous. I know it's the internet, but have some decency and respect for your interlocutors. You guys are all professionals right?

984 Upvotes

324 comments sorted by

View all comments

42

u/[deleted] Feb 16 '21

I've worked in data science for over 10 years and I've never written an SQL statement. I did use a little bit of ORM to interact with a database, but I didn't write the SQL myself. Everywhere I've ever worked at we used NoSQL, Hadoop, Spark, Kafka etc.

I don't use a lot of pandas either. I mainly use spark through Scala to build data pipelines. I've contributed pull requests to pandas back in the day, but if you asked me random trivia I wouldn't be able to answer it because it's not something I use on a daily basis. Doesn't mean I wouldn't be able to relearn it. I've also done quite a lot of database work, just not with SQL. I'm perfectly familiar with relational models and how SQL works and would be fully capable of learning it. It's just not something I need so I don't bother.

Why do you need the skills that make you good at leetcode in your job? Because you need to be able to look at the problem and tell me what kind of a problem it is and what do you need to solve it. And you need to have sufficient skills to look at a solution you wrote (or someone else wrote) and critically evaluate and determine if you can do better.

Most natural phenomenon can be represented as a graph. It can be bus stops, it can be customers, it can be girls running away from boarding school (ever heard of social network analysis?), it can be packets going around the internet, it can be anything really. And knowing how graphs work is super useful.

I am convinced that people that complain about leetcode are simply incompetent, feel very self-conscious about it and are precisely the people that should do a data structures & algorithms course.

The simplest example I can think of that most data scientists fail in an interview is the Stones and Jewels or to be more precise, the variation where you give the counts for each jewel.

A large portion of data scientists I give this problem to fail to complete the task in the allocated timeframe (30 minutes). They try to start to install numpy and pandas and spend 30 minutes googling/browsing pandas documentation to see if there is a function that does something like this and maybe try to parse the data somehow.

A small portion of data scientists are competent enough to understand what is asked of them and write a loop:

count = 0
for s in S:
    if s in J:
        count += 1
return count

My follow up question is when I hand them a gigabyte of data. Almost everyone fails to handle it in a reasonable way even after giving them hints about data structures and time complexity.

A tiny majority will recognize the algorithmic complexities of data structures involved. Lookup over a string is not great in terms of time complexity. How about using a data structure that uses hashes instead?

What would you really use this type of thing for? I'd say that counting things is pretty important in data science. I've never seen perfectly cleaned data in the real world and for example counting the frequency of something as a feature comes up quite frequently.

I've seen it before. Someone complains that the server with 128GB of memory and 24 CPU cores is "too slow" and they "need a bigger machine or even a cluster". Turns out they wanted to load the data into pandas first and then try to engineer some features out of it. Replace that pandas monstrosity with ~10 lines of vanilla python and you can handle the dataset on 1 cpu core and 512MB of memory. This is just basic data cleaning/preprocessing stuff.

If anything, I'd argue SWE's don't need leetcode because most of them won't work at Google and won't deal with large amounts of data. No need for leetcode for someone doing CRUD and the largest n they see is like 100 things to display on a web page. Data scientists by default deal with large amounts of data and leetcode is super duper important because as n goes up, everything goes to shit if you don't think about complexities. You need leetcode as a data scientist.

I find that most companies really struggle with getting actual benefit out of their data science teams precisely because they hire a bunch of statisticians and mathematicians and don't pay attention that this ain't an academic curiosity anymore. It's the real world with real world problems like limited resources and wanting results in 20 seconds, not 20 hours. For example in the real world you're probably generating data at a steady pace and if you can't keep up with it, you're in trouble. A lot of people get away with throwing more computational resources at it, but then they have to justify to the bean counters

Shipping linear regression that took you $1000 in man-hours to develop into production on a $20/month instance is better than having a state-of-the-art model that took you $100 000 in man-hours only works on your laptop and will require another $250 000 to even have a chance of running in production. It's going to be a lot harder to break even.

Now, full disclosure. I used to teach computer science and math to undergrads and high school kids during grad school. Leetcode problems are toy problems designed to explore concepts in a fun way. They're like the worded problems where John had 200 watermelons and Jane had 2000 watermelons. They're not supposed to be "real world" and they're elementary by design (as in you don't need any background knowledge to solve them).

I don't recommend "real world problems" to weed out candidates because it's basically pure luck if someone has the exact knowledge required. I for example didn't work with SQL during my career and if all you did was ask me SQL questions you'd weed me out. Never mind that I created fully custom data warehouses for a living for big data from scratch because back then we didn't have so many options. It just wasn't with SQL.

13

u/[deleted] Feb 16 '21

the server

Sir with all due respect, I just solved that problem on leetcode using a hash in less than 2 minutes. I specifically didn't look into your solution and dove right in to measure my competence (faster than 89% of all submissions). Another way you can try solving this is sorting the two strings and then using a two pointers to guide through the sorted string. This wouldn't use any extra space complexity, but would result in O(2 * nlogn) in runtime. You'd also get into lots of edge cases if you don't get the logic right.

If people can't solve this simple problem, then yes, it's clear as day that you should not pass them along. And I'm sorry that this is a big chunk of people you've interviewed. The types of questions I was referring to is this: https://leetcode.com/problems/minimum-knight-moves/ or any of those island questions where you have a grid and you need to move pieces in a certain way using recursions and helper functions.

Also, it seems to be the case that you've been focused on Data Engineering in your career. Pandas isn't used for data pipelining but for data munging, feature engineering, etc. that's crucial for ML process. It's also good for data visualization, such as crosstabs, etc. Also, most companies I've seen don't use NoSQL, even medical data companies that gather disparate forms of diverse data into one mega database.

3

u/Kengaro Feb 16 '21 edited Feb 16 '21

Another way you can try solving this is sorting the two strings and then using a two pointers to guide through the sorted string.

Why would you use 2 pointers? That is like hunting birds with a sword...

1

u/[deleted] Feb 16 '21

No not really. I just solved it using two pointers on leetcode as well. So if you work with strings and pointers, it's really tough. But if you convert char in jewels/stones into ascii value, it becomes a simple "find common element in two sorted arrays" problem.

def solution(jewels, stones):
    
    jewels = [ord(i) for i in sorted(jewels)]
    stones = [ord(i) for i in sorted(stones)]
 
    i = 0
    j = 0
    count = 0

    
    while j < len(stones) and i < len(jewels):
        if stones[j] < jewels[i]:
            j+=1
        
        elif stones[j] == jewels[i]:
            count+=1
            j+=1
        
        elif stones[j] > jewels[i]:
            i+=1
              
    return count

It's super slow, as you can expect, but it works, and no extra space (if you don't count the transformed jewels/stone arrays).

→ More replies (8)

5

u/[deleted] Feb 16 '21

Why would you want O(nlogn) when you can just do O(n)? Looking up using hashes (such as with a set) is O(1) and iterating over a list is O(n). This is very basic DS&A knowledge and understanding what you're doing is important to solve problems.

I am well aware what pandas is used for considering I contributed to the project quite a bit a few years ago. I simply haven't used it recently because the data I work isn't a good fit for pandas due to the size and the fact that it's not just rows and columns. If you asked me pandas trivia, I'd fail the interview because that's not something I use on a daily basis.

10

u/[deleted] Feb 16 '21

Because to do O(n) using hashes you need extra space complexity O(n). By doing O(nlogn) you're sacrificing runtime for no extra space. One basic principle of SWE is tradeoff between these two and what makes sense to use given problem at hand. There are times when interviewers specifically ask for no extra space. Usually those require O(n) runtime using some fancy algorithm you had to memorize. I've found that O(nlogn) using pointers after sorting can work in many situations when you don't memorize those algorithms. Good and understanding interviewers also realize this and usually ask you to solve in O(nlogn) after sorting and using one or two pointers using while loops or recursions

-2

u/[deleted] Feb 16 '21

And why do you think that you need extra space to store the jewels in a set (or the counts in a dict) as opposed to storing them in some other data structure?

2

u/prosocialbehavior Feb 16 '21

you lose

2

u/[deleted] Feb 16 '21

Lose what?

Space complexity of using a hash table (so set or dictionary for example) is exactly the same as using an array (such as a list) or any other data structure. It's O(n). There is literally no reason not to use it in this case. You have to store the data somewhere anyway so might as well use proper data structure for the task at hand.

There is no tradeoff. There is a bad solution and there is a good solution.

1

u/[deleted] Feb 16 '21 edited Feb 16 '21

Dude what you said is so wrong it's not even on the map. What if I then asked the same Jewels question but said no extra space complexity (just O(1) no O(n) like hashmaps). What would you do then? Now there is "literally every reason not to use hashmaps".

The fact that you disregard tradeoffs between space and time complexity is really alarming. Actually SWEs would be horrified by your comment. The concept is literally called "Space–time tradeoff", it's on wikipedia under computer science. I'm kind of shocked by your answer and level of approach to CS questions, and beginning to suspect why data scientists are getting such bad rep on programming skills.

→ More replies (3)