Getting Prepared for Python Coding Interview Questions for Data Science and Machine Learning Positions

Many of Data Science job interviews require the applicants to complete two or more coding exercises which are typically taken either during an interview or as a take-home assignment. Note: not all interviews!

Before getting started, do we need all this?

Not necessarily. We are talking about common strategies boosting the probability of landing a job. I have had some interviews without any coding exercises. It is just a matter of continuous self-improvement, learning and having fun!

How difficult these technical interview questions are?

Depending on the nature of the job and the company which you are applying to, the difficulty level of the questions varies, but the majority of questions float around the medium range for Data Scientist positions.

If you are applying for a Machine Learning Engineer/Developer role; for instance, you should expect more difficult coding questions appearing in your technical interview.

Again, there is no universal rule and everything depends on the nature of the job, the company, and the examiners.

Now, when we are talking about the level of difficulty, it is not just about the complexity of the potential solution to the question, but it is also about some details, such as time and space complexity of the suggested algorithm, and being able to consider boundary or edge cases. This might be frightening for applicants who do not come from a computer science background, but the good news is that part of the solution to these problems lies in the amount of practice which you put to it. Moreover, not all Data Science or Machine Learning positions maintain very high standards in evaluating coding capabilities of the applicants.

So, what is the take away here?

My suggestion would be to get prepared for more difficult problems and build the coding core as solid as possible while you are searching for a job. I know it is time consuming, but you will be armed with a reasonably solid toolbox that can both benefit you in better handling the coding assignments and in more effectively writing your codes after landing a job.

This is not directly related to the purpose of this post, but you might ask yourself what if our job does not entail too much coding?

In response to this question, I would promise you that at some point in your future career path, you will need to know at least how to productionize your developed machine learning models, and building Python modules and packages is one reasonable way to achieve this goal. Hence, we need to have solid coding skills.

What are these coding questions and what should we learn?

Well, I do not have a straightforward answer to this question, but I can give you few examples that I have faced in the past. I suggest not to answer these questions now, and please do not make any encouraging or disappointing conclusions at this point, for it is too soon.

  1. Move all the duplicated numbers to the right of an array. Constraints: time and space complexity should be O(n)
  2. Remove the duplicates.Constraints: time and space complexity should be O(n)
  3. Remove all the occurrences of a number in an array Constrain: no new array must be defined
  4. Find the first and last position of a number in an array
  5. Find the missing numbers between 0 and 9 in an array
  6. Find the lowest common ancestor of two pointers in a tree
  7. Find the minimum number of swaps required to sort an array of integer numbers in an ascending order

And the list goes on and on.

How do we get prepared to answer these questions?

The answer depends on the question. If we are talking about simple to medium questions which do not require any knowledge about the algorithms, trees, graphs, and other similar concepts, then you can go ahead and signup to one of the coding interview preparation platforms and start practicing.

If the question is more challenging and it requires prior knowledge about the algorithms, you need to first familiarize yourself with these algorithms and concepts, then start practicing.

If you have enough time, I strongly suggest to learn some concepts, like data structures and associated algorithms first. Afterwards, you could choose your path based on the positions which you are applying for.

What are the data structures, concepts and algorithms that we better learn?

Data Structures

  • Big O, time and space complexity
  • Arrays (most common)
  • Hash Tables (most common)
  • Linked Lists
  • Stacks and Queues
  • Trees (very important for software developer positions)
  • Graphs

Algorithms

  • Searching: Linear and Binary Search
  • Tree Traversals: BFS and DFS
  • Recursion
  • Dynamic Programming (not that common in the interviews)

Where can we learn these concepts?

There is no shortage of sources for these concepts. You can find plenty of online courses on Udemy and Coursera. If you are not comfortable with online courses, just try and search each topic separately, and you will find tons of material. Meta has put up a good interview guide where you could find some videos explaining some of these concepts. Search this on YouTube: Cracking the Facebook Coding Interview.

Now that we boosted our knowledge, where can we practice?

This is the most important part which plays a pivotal role in preparing us for the interviews. Practice!

How many problems should we complete before we prepare?

I would say there is no magic number, but based on my experience, above 100 would make us more confident in handling the interviews.

Where can we practice?

There is a plenty of platforms. I like leetcode, CoderPad, and HackerRank.






To view or add a comment, sign in

More articles by Yaser Zerehsaz

Others also viewed

Explore content categories