How to answer a coding question in an Interview? Last Updated : 14 Sep, 2018 Comments Improve Suggest changes Like Article Like Report A lot of technical interview rounds focus on coding questions. You are presented with a pen and paper and asked to suggest an algorithm to solve the question followed by the code. Here's a general guide as to how you should go about answering such a question. 1. Clarify the problem statement: The first thing to do is to clarify the problem statement. It's important to understand the problem clearly before attempting to solve it. For example: I was asked in an interview: What's the probability of getting three tails when a coin is tossed three times. A lot of students answered 1/8 and couldn't make it to the next round just because they did not ask the right questions. How can you answer this question without knowing if the coin is biased or not? It's vital you ask the right questions. 2. Constraints Once you are clear with the problem statement you need to ask if there are any particular constraints that you need to adhere to. 3. Observations Any problem has some specific peculiar behavior associated to it.You can try out some examples and list out all your observations. Remember you need to explicitly tell the interviewer all your observations. 4. Approaches: On what lines you think? This is the most crucial part in the entire interview process. If you get this part right there's a high probability you will make it through the round. What makes you think that you need to approach a problem via dynamic programming or backtracking or any other algorithm for that matter. The interviewer needs to know why you rejected a certain approach to a problem and selected the other. Try to link various concepts you have studied and slowly start ruling them out. If you plan to use a data structure to solve the problem, specify the reason as to why you chose to do so. If you get stuck try the brute force approach. This would work out for most problems. Once you are done with narrowing down the approach and you think you might have a solution, discuss it with the interviewer. If the interviewer suggests something different gracefully accept it and start thinking along those lines. Dont be to rigid with your approach. 5. Edge Cases and counter examples Once you are certain for a particular solution make sure you check out your approach for all the edge cases. 6. Writing the Code: Make sure: a. Your code is readable. b. You specify comments in your code c. Dry run your code with a few examples before showing it to the interviewer. With these six things in mind, I'm pretty sure you would nail the coding interview. However these suggestions won't work if you are not well versed with data structures and algorithms. So, solve problems on Geeksforgeeks, work hard and you'll make it to your dream company. Comment More infoAdvertise with us Next Article How to answer a coding question in an Interview? A Ankit Jain Improve Article Tags : Misc Interview Experiences GBlog TechTips Placements Experiences interview-preparation placement preparation Career-Advices +5 More Practice Tags : Misc Similar Reads Housing.com Interview Experience | Set 3 (On-Campus) I was interviewed by housing.com through campus placements. Here is my interview experience. Round 1: Resume based and 1 coding question. Briefly discussed about projects in resume and questions were completely related to projects mentioned. Coding question: How will you determine the repetition ele 2 min read Amazon Interview Experience | Set 393 (On Campus For Internship) Online Coding Round:- There were 2 coding questions and 20 MCQ's. Given an array find all the triplets having their sum of elements less than a given number k. GeeksforGeeks LinkFind The N-th Magic Number. 1st Interview Round(Face To Face):-The interviewer was very friendly. He went through my CV a 3 min read TCS Interview Experience | Codevita Season 8(Off-Campus) On 31st July TCS Codevita season, 8 interviews are being scheduled for my zone in Kolkata branch of TCS, Gitanjali park. As I called for an interview, I entered in an interview room, there was a panel of three interviewers and one of them is an HR so basically both of the round Technical + HR is hap 5 min read Amazon interview experience | Set 384 (On-Campus for FTE) Online Coding Round: Platform: Hackerearth Time: 1.5 hr Questions Format: 20 MCQs + 2 Coding Questions MCQs were based on Data Structures, OS, Networking, etc. Coding Questions: 1)find maximum j-i such that arr[j]>arr[i] Expected time complexity: O(n) 2)find maximum of minimum of every window siz 5 min read Deutsche Bank Interview Experience | Set 6 (On-Campus) Deutsche Bank visited the campus and coding round included 10 MCQs based on Sorting and Data Structures. 2 coding questions: 1. String is given and left and right integer is given. Left means number of character to be rotated left, and right means number of characters to be rotated right. Find the r 3 min read Amazon interview Experience | Set 416 (On Campus for Internship) Coding Round There were 2 coding questions (10 marks each) and 20 MCQâs from various core concepts ( OS,DS,Algorithms,DB,C language etc ). Question 1 : https://www.geeksforgeeks.org/given-a-string-print-all-possible-palindromic-partition/ Given a string, find all possible palindromic partitions of g 4 min read Amazon Interview | Set 119 (On-Campus for Internship) The selection procedure consisted of an online round followed by two Personal Interviews. Online Round: The first round had 20 mcq consisting of 3-4 questions from aptitude, 2 questions from os and rest were from Basic C and Data Structure. There were 2 coding questions as well. Question 1: You are 3 min read TCS Interview Experience | Codevita Season 9 I want to share my interview experience for the codevita. Basically TCS will be recruiting for the digital package through one of its process known codevita contest. There will be 6 questions which we have to solve in 6 hours of time. If you do atleast one program in this contest there are chances t 3 min read Oyo Coding Interview Experience Online Round :  Oyo Coding visited our campus in the last week of August. Round 1 was held on Hackerearth which comprised of around 25 MCQs and 2 coding questions. MCQs were from topics like Data Structures(mostly), Aptitude, Operating systems and DBMS. The coding questions were Minimum no of ways 2 min read Amazon Interview experience | Set 128 (For SDET) I was interviewed for the position of SDET-1 few days back at Chennai. Here is my interview experience: Coding round (Full code required): 1) Given a linked list. Check whether it is a palindrome (without using any extra space). 2) Write a program to return the mirror tree of a given binary tree. 3) 3 min read Like