How to prepare for machine coding round
Machine Coding is a new format of interview that finds its place in the preliminary rounds of major tech companies like Uber , Flipkart , Swiggy , Ola ...etc.
If you’ve discovered this article, then I assume that, you’re either preparing for interviews or planning to give one. All the best !
After discovering scant resources, I’ve decided to pen down my thoughts and suggestions pertaining to this round.
In this article I will explain
- What is Machine Coding ?
- Sample Problem
- Things to consider
- Resources
What is Machine Coding ?
While it is often confused with a coding round on HackerRank / HackerEarth, Machine Coding is an entirely different format that tests your ability in low level design.
In this round, you’ll be given an open ended problem statement with clear and concise expectations. It could be designing a parking lot /library management system / ride sharing platform..etc and the expectation is to write clean and extensible professional level code.
The candidates are allowed to code in IDE of their choice on their personal laptops and they are free to explore online resources. Most companies have a time limit of 90 minutes for this round.
Sample Problem
Let us dive into a sample problem — Cab Booking Platform
Problem Statement:
+ Build a Cab Booking Platform to allow a rider to book a cabDetails:
+ The location is represented as (x,y) co-ordinates
+ Distance between two points is euclidean distance
+ A cab only has one driver
+ Sharing of cabs is not allowed Application to Build:
+ Register a rider
+ Register a driver/cab
+ Update a cab's location
+ A driver can switch on/off his availability
+ Fetch history of all rides taken by a riderExpectations:
+ Demonstrable code - either with CLI or WebAPP or API or MainMethod
+ Code should be extensible
+ Clean professional level code
+ Functional Completeness
+ Proper Modeling of entities
You can find the solution here
Things to consider
Clear out the expectations
Each company has their own criteria of evaluation. Some are interested in runnable code while some are interested only in the modeling / low level design.
It is important to clear out the expected outcome and call out any assumptions that you make while modeling the entities
Define Interfaces
Whether you are building an API or library, It is important to define clean and proper interfaces
Handle Exceptions
Think of all the possible cases that could go wrong with the API and handle them.
For eg: What if a rider/cab tries to register multiple times? What happens if the rider tries to request for a cab while on a ride ? ..etc
Concurrency
Try to handle concurrency wherever it is applicable.
For eg: What happens if two riders tries to book the same cab at the same time?
Extensibility
Make sure that your code is extensible for further use cases.
For eg: What if sharing of cabs is allowed ?
Keep it simple
There are ’n’ number of ways to assign a rider to a cab. Do not lose out time by trying to implement complex algorithm/optimize the time complexity. Choosing a right algorithm is good to have but not mandatory.
Timing
Timing is the key to this round, It is important to call out assumptions and implement only those entities that are essential.
Tip:
- Define your entities and relations between them like in a UML for the first few minutes and implement them later.
- All those IDE shortcuts that you’ve been learning will be of great help here.
- Follow greedy approach while implementing the features, implement the higher priority ones first.
Miscellaneous
- Your modeling should involve OOP concepts like Inheritance, Encapsulation, Abstraction, Polymorphism
- You do not have to use spring or define schema in sql/nosql databases. You can use in-memory data structures to store the data. However, please note that, the criteria is different for different companies.
- Use enums wherever applicable
- Keep an eye on naming conventions of methods / variables. Make sure that the code is self explanatory, In case if something is too complex to discern by the interviewer, add comments.
Resources
Some resources that you might find helpful in the preparation
- Thinking in Java by Bruce Eckel (If you’re a beginner in Object Oriented Concepts)
- https://www.educative.io/courses/grokking-the-object-oriented-design-interview/
- https://www.geeksforgeeks.org/object-oriented-programming-oops-concept-in-java/