How to answer a coding interview question | by Tuan Nhu Dinh | Towards Data Science

This blog is a part of my “15 days cheat sheet for hacking technical interviews at big tech companies”. In this blog, we focus on a step by step approach to solve a coding interview question.
The coding interview sections are designed to reveal how you think, communicate, and solve problems. Hence, giving the correct and perfect solution to a problem does not guarantee a positive outcome, you will be judged on how you come up with the answer. The below are the steps I usually take to not only give myself the best chance of answering the question correctly, but also give the interviewer a decent feel for how I handle the question.
You are often asked to give a short introduction about yourself in almost every coding interview. It is a critical part of making the first impression and that is the only predictable question. Hence, do prepare yourself with a concise introduction (under a minute or two) following the format:
A sentence about your name and general background.
A few sentences about your professional experiences after university. If you are fresh graduates, focus on your internships and school projects. Otherwise, select one or two challenging projects or the projects required relevant skills to the position you are applying.
Finish with a statement saying why you are seeking a new job opportunity and why you are interested in the role you applied for.
“Hi, I’m Dinh Tuan and I’m a backend engineer with over six years of experience specialising in designing and implementing high scale and high availability backend system. I started my career in SEA Group, one of the biggest tech company in South East Asia. During 5 years in SEA, I led the backend team implementing a gaming platform which serves 3 millions concurrent users and 500 thousands request per second at the peak time. I also helped to grow a team of 30 engineers in Vietnam after they acquired a Vietnamese startup in food delivery services. In early 2019, I joined Datarobot, a unicorn in Boston, United States. I work under code and architecture team to design and implement the feature to support multiple external compute clusters (including both Kubernetes and Hadoop).I’m interested in the software engineer position in Facebook because I would like to grow my technical skills further in a large scale social platform.”
You are usually given the opportunity to ask questions at the end of the interview. Skipping this part means missing out on the opportunity to learn about the nature of the work and the culture of the organisation. Moreover, a good question can also showcase your communication skills, demonstrate your interest in the role as well as make a good impression. Some of my favourite questions are:
1. What technology is the company/ your team currently using?2. What is your favourite thing about working for the company?3. How much say do developers have regarding the products?4. What qualities make a software engineer excel at this company?5. How flexible are the working hours?6. How will role performance be measured? What metric will role performance be measured with?7. How has your role changed since joining the company?8. What are the most challenging aspects of the job?9. What is the current team composition like?10. What resources does the company have for new hires to study its product and processes?
Do read the question carefully. If the question is not written, do repeat what you listen from the interviewer.
Do work through the given examples or come up with some examples. It does not only help to ensure your understandings, but also allow you to pick up on patterns and generalisations to answer the question.
Do clarify any assumptions you made such as input format or range.
Do come up with the easiest and most obvious solution.
Do look for improvements and try to come up with a better solution.
Do think out loud, talk with your interviewer what you’re thinking. It keeps them engaged, allows them to understand your thought process as well as gives them a chance to point you in the right direction or stop you before you waste too much time.
Do ask for hints if you’re stuck.
Do work through some examples with your solution if it is not so trivial. You can also use whiteboard to work through your solution if it is necessary.
Do state and explain the time and space complexity of your approaches.
Don’t jump straight into writing code. You should only start coding after your interviewer understand what you’re going to do and give you the green light.
Don’t keep silent for too long. If you are stuck, try to speak out the points making you confused. If you need to be quiet to think, just let the interviewer know (but keep it less than a minute).
Don’t ignore the information from the interviewer. Every piece is important.
Don’t interrupt your interviewer when they are talking.
Don’t get frustrated or discouraged. Take a deep breath and keep trying by walking through more samples, thinking about different algorithms and data structures.
Don’t try to bluff it. If the interview hints something you are unfamiliar with, just admit it and move on.
Do explain what you are writing or typing.
Do follow the good coding style (such as using descriptive variable names) and structure your codes well (with functions and classes if they are necessary).
Do speak out your understanding about the algorithm, data structures or built-in functions you use.
Do ask for the permission to use the built-in functions or skip some input checking. They may allow you to get away the implementation of some trivial functions or get back later if there is enough time.
Do pay attention to your hand-writing if you are required to write on the whiteboard. You need to ensure it readable and well-organised (especially space between words and lines).
Don’t write pseudo code. Although you don’t need worry too much about the syntax, you are expected to deliver bug-free production-ready code.
Don’t keep silent for too long.
Do think about how you will test your code, list down corner test cases.
Do run through your code with your interviewer for the test cases.
Do fix any bugs that comes up when scanning your code with the test cases.
Do look out for places where you can refactor.
Do evaluate the time complexity and space complexity of your written code.
Do suggest any better solution if it is existed and more time is given.
Don’t argue with the interviewer. As the interviewer is familiar with the question, they are unlikely wrong. Take their feedback and think about it carefully.
Do ask the questions to understand the work and company culture if the interview gives you that opportunity.
Do thank the interviewer for their time.
Don’t ask too many questions and try to end on time.
Don’t asking about your interview performance.
Don’t continue discussing about the coding problem as it is over.
References:
Crack the coding interviewTechnical interview handbook
Crack the coding interview
Technical interview handbook