Cracking the Machine Coding Round

Abhishek Deb
9 min readDec 13, 2020

This article is only for lateral hire who have an experience of a year plus since machine coding round is not a part of campus hiring and only lateral hire go through this process

Recently I got a chance to appear for an interview with Flipkart.
After getting many responses to share my interview experience finally I came up with this article that focuses more on the Machine coding round that is not much common in most of the companies hiring out there.
Either it’s an SDE-1, SDE-2 or any tech opening at Flipkart Machine coding is one of the most significant parts of the hiring process but since not much resource is available for the same would try to cover as much as possible in this article.

What is machine coding round ?
In this round you are expected to solving a design problem(Not that complex for SDE 1) in 90 minutes . You have to design and write a clean code that is modular and extensible also look for all the corner cases so that the solution doesn’t fails at any point of its execution.The question has a fix set of requirement with some constraints that has to be implemented to get a clear pass.This will be followed by a code review process where the interviewer(Might be 2 in some cases) try to do a code walkthrough and understand your design logic.

Coming to the next part “What is not expected from your solution ?”
Things that you can assume are not a part of scoring your solution and hardly have any impact on the final feedback.

What is not expected?
1 In this round you should not worry about the space or time complexity of the data structure you are using or the algorithm that you have used because you just need to have a working code these thing can be handled in the production level

2 No need of using a Database neither they will ask you to do so as in most of the question will be asked to store the data in memory using some DS and get the expected outcome

3 In such round the UI part is not required the code in generally a command line based and need to be shown in that way only

So coming to “What is expected from your solution ?” for it to clear the machine coding round(Most of the company has the same type of expectation by still depend on the role SDE1, SDE2, and so on)

What is expected from your solution?

Your code should be executable ,demonstrable and handle all exception cases gracefully (Very Important)

Your code should have modularity ,readability and it must be self explanatory during the code review process

If required you should be able to easily add new feature to the existing code with minimal changes

Your code should fulfill all the functional requirements as given to you properly

Code should have a main function or some menu driven interface to test it

One optional exception is to have some test case either unit or integration test written for your code (It will be adding more weightage during scoring)

Note: One of the most important parts of this process is your code should be executable at the end even if you are not able to completely implement all the functional requirement reason being to score your solution or to judge is it a pass or fail they interviewer should be able to at least able to execute some test cases and get some output but if the functional requirements are met and the code is not executable testing can’t take place.

This was pretty much about the process and what you should do in it.
Moving to the next segment How to prepare for the Machine coding round and what should be your thought process for a design-based question and yes some sample questions that might be asked in your interview with the solution.

How to prepare for the machine coding round ?

There are a few things you should be good at before you appear for the machine coding test some of these are listed below

You should be good at Object-Oriented Coding

In this round, the general expectation is that you’ll write object-oriented code and will try to maintain the separation of concern properly
When I say Object oriented it basically means rather than writing everything in a single file without any classes and proper methods won’t be accepted in this round. You are supposed to write the code in a such a manner that you create multiple classes each containing properties related to one particular entity and methods only related to that.

Note : One key point to highlight here is for all the python developer that in case of python a single file can contain multiple classes yet try to create seperate file and import them in the final driver code that look pretty much good :D
Language hardly matter in this round you can use CPP , Java or Python but stick to the OOPS concepts and its coding pattern.

You should always write clean and readable code
When I say readable it means your code should be self explanatory and it should have the appropriate variable name and method definition
In the code review process the interviewer should be able to understand much of the code via the comments and the meaningful name given to the variable and functions.
Try not to write too lengthy method rather if there are multiple things that has to be done in a method break it down into sub parts like method_name , method_name_util where the util is a sub part of that method
Try to keep the method name relevant to what is actually been done inside it like if you want to create a method that will handle the operation of creating or trigger a booking event for cab booking application like OLA it can be written as

Python :
def book_cab(RiderDetails,Source,Destination)
Java :
public void book_cab(RiderDetails riderData, String Source, String Destination)

The above code is just a sample how to use appropriate function name and comments in code while keeping the variable naming meaningful as well so that the interviewer need not have to go through each and every line of the code and can directly skip into the functional testing part

Tip : Even though your code is fulling functioning but if your code is only machine readable and not human readable you might fail in this round since sometimes it's more about writing clean code rather than writing working code in somecases So try to keep your code working as well clean as much as possible

Your code should be always extensible

While writing the code try to make sure that your code can accommodate new features with minimal changes in the existing codebase extensible code is something that is much required while you are actually developing a real world application
Simple example:
Suppose you were asked to create a snake and ladder game and initially it was decided that the game will be played with a single dice so you created a function that generate a pseudo random number between 1 to 6 as follow

def roll_the_dice():
return random.randint(1,6) [Original Code]

Now once you are done with your code and you were ask to make a small change rather than using one dice we want to use two dice now so without making much change if we just make a small change to the roll_the_dice method we are done with adding a new feature to the existing code

def roll_the_dice():
return random.randint(1,6) + random.randint(1,6) [Updated code]

Time Management (Very Important)
Since you have a pretty much limited time for your machine coding round somewhere in between 90 to 120 mins . You will have to manage the time properly so that you make the deliverable on time.
You can use your time something like this
Invest the first 10 min to understand the question properly and try to figure out all the data structure you will use and how various methods will interact with each other
Use the next 5 mins to write down all the entities according to the given requirments and mark down there role in each method
Use the next 70 mins to code the solution and write the API for each functional requirment and also some testcases
Once you are done with this part use the last 20 mins to debug your code and also to write the driver part that can be use to test it
Finally once you are done with the code you will now have 15 mins to do a code review with the interview and in this duration you might be asked many question over your design logic and why you preferred such a DS etc

To clear this machine coding round I hope these are the most basic things in which you should be well versed but coming to the key point how to start off with it so my opinion would be to try writing the code on paper and once you are done with it check it yourself that without knowing the question were you able to understand the core concept or logic behind your code try to solve simple question in the starting like creating a tic tac toe game or something like a simple app that can take a name and find there contact number etc and once you are confident with it try to work more on the OOPs part and refactor your code to make it more readable. Also, I would recommend you to go for a peer review if you have people around you who can help you out with going through your code and trying to understand your logical approach.

How to solve a Machine coding problem ?

Till now I hope I have covered much of the information regarding this round but to wrap it up I will try to tell you about how you can attempt to solve a design question and get it done successfully

Note : I will be taking an example of cab booking application to explain each steps in details you can find the detailed question in the link attached at the end of this doc

There are a few steps that might help you in getting a appropriate solution

Step 1 : Try to figure out all the possible entities that is present in the given problem statement along with the properties they have for example in the given application we have a passenger who has properties like name , age , gender , total_rides_taken , average_rating similarly we have a driver who has properties like name,age, gender ,vehicle_details,average_rating,total_earning,
current_location etc in both the cases we will have a class for each with their default constructor along with some getter setter for each properties
Tip : Try to maintain the folder structure and keep the model file in a folder named as models it will have a good impact overall

Step 2 : Then comes the core business logic or the main segment of the code in which you need to think first how you are going to implement each of the feature realted to one particular entity and once you are done with it create seperate class for each business logic and you can call it as a service or manager .This manager will be used to interact with other models and services inorder to avoid ambiguity in the code or any type of crosstalk .Ideally you should place these file in a folder name as service or manager
Tip: Before moving to the coding part once you have the logic with you try to priotize the feature that has to be implemented first so that if you run short of time you can drop of the non essential feature and move to the step 3

Step 3 : So once you are done with implementing the core logic of most of the API as given to you in the question you should ideally move to this step at the end of 70 mins because you will have to make the code execuitable to clear this round.
At this point you will have to make sure you manage your time appropriatly and don’t waste much of the time in implementing the feature rather then making the code demostrable

Step 4 (Optional) : You if have plenty of time still left with you then try to create some unit-test cases or integration test for your code this will make the walkthrough process easiser and will speed up the process since the basic cases are already covered from your end

This was all about the machine coding round and how you can prepare for it.
You should always start off with a core object-oriented language like java, Cpp, or python and try to first solve the question on paper by drawing a block diagram for a given question and then move on to the coding part.
I will be sharing some question which is similar to the question that might be asked to you during a Machine coding round hope that might help you to prepare well.

The link to the question has been attached here: https://docs.google.com/document/d/1YdlpKqL21qyT8StHf-Z9duL4e6leE7KsIWyMGYQLt_I/edit?usp=sharing
Will be adding more question to the same docs soon :)

If you still have any doubts or queries you can hit me up on Linkedin: https://www.linkedin.com/in/deb-abhishek/ or Instagram @abhi_deb48

Happy Coding :)

--

--

Abhishek Deb

Working as a SDE 1 at flipkart having good knowing in the field of DSA , problem solving , machine learning and android development.Programming language Python