Programming Interview Questions and Answers for Coders
By Indeed Editorial Team
Updated October 9, 2022
Published June 21, 2021
The Indeed Editorial Team comprises a diverse and talented team of writers, researchers and subject matter experts equipped with Indeed's data and insights to deliver useful tips to help guide your career journey.
Interviewing for a programming job allows you to highlight your skills and express why you're the best fit for the job. It relies heavily on a combination of theoretical and practical questions. In this article, we discuss some sample questions and examples of how to respond.
General programming interview questions
Here is a list of general interview questions you could be asked.
Have you ever experienced particularly difficult situations when coding?
The interviewer will want to know how you manage difficult programming situations and how you find the solution to those problems.
Example: "When I was working at my previous job, I took on a project that had already been started by the senior developer before me. He'd gone on sick leave and didn't have time to finish it. When I received the project, there were several bugs. However, the original coding was much different from my style. I spent several weeks writing the code to match my style and to, eventually, remove the bugs."
How have you managed conflict with coworkers in the past?
A recruiter will ask you this question to determine how you work in a team and how you handle interpersonal relationships at work.
Example: "When I've experienced difficulties with coworkers, I've always dealt with them by talking directly to my coworker. I'll always remain respectful to the person in question and don't want to cause rifts in my team, so I'll take the time to discuss the situation calmly and express my needs moving forward."
Why do you want to work here?
Show the interviewer what you know about their company and that you researched them before the interview. Prepare your answer in advance to ensure they're unique and well-thought-out.
Example: "I only apply to companies that coincide with my values and morals. I want this position because I have both personal and professional experience that will contribute to the company's future."
How do you handle pressure?
Programmers deal with a lot of pressure, which is why a recruiter will want to know whether you can work with feeling stressed or when having a lot of tasks to prioritize.
Example: "I use stress as a motivator. When there's a lot of pressure at work, that means I have something to overcome. Whether it's deadlines or a heavy workload, I focus on accomplishing one thing at a time until I'm done."
Related: Interview Preparation Tips
Questions about array coding
These questions are common in any interview because arrays are the components of data structures that store information. An interviewer can ask several questions about arrays, ranging from how to reverse an array to how to sort one. To answer these questions, you need extensive knowledge about data structure going into the interview.
The recruiter will also ask you about arrays to understand how you interpret them across multiple programming languages. Here are some questions a hiring manager may ask you:
If you're presented with an array of 1 to 100, how would you find a duplicated number?
Interviewers ask this question to determine your theoretical knowledge and your processes.
Example: "The easiest way to do this is to create a hash set. I transfer all numbers from the array to the hash set, so there are no duplicated numbers. If one of them pops up as a failure, I can find a duplicated number."
If the array was unsorted, how would you find numbers 1 and 100?
In this case, the interviewer is trying to see whether you can provide step-by-step instructions to solve a coding problem.
Example: "There are a few steps involved in finding values in an unsorted array. Firstly, I find the front and back of the index and initialize them. If the front is larger than the rear, I mark them as false. From here, I can check for the element. If the element is found, I can return the index to true."
Read more: Technical Skills: Definitions and Example
If you have several pairs of duplicated arrays, how do you find particular duplicates?
Interviewers ask this question to determine how you prioritize tasks when they have several to do at once.
Example: "First, I start by initializing and declaring the array. From here, I can choose to use two loops: the outer and inner loop. The outer loop selects an element and the inner loop will compare the element I've chosen to others in the array. From here, I'll be able to find any duplicates."
Questions about linked lists
Linked lists are also commonly discussed in interviews because of their importance in programming. Linked lists go hand-in-hand with arrays and also store data linearly. They ask questions about linked lists to determine the candidate's competency in computer science.
Moreover, evaluating candidates on linked lists tells the interviewer whether you can express reasoning to solve complex problems. By asking about linked lists, interviewers gain a better understanding of your recursion knowledge because the two are often related.
If you want to answer these questions with confidence, go into your interview with knowledge of recursion. Here are some questions a recruiter may ask about linked lists:
When dealing with a singly list, how would you find an element that's placed in the middle?
This is a general question that allows you to show your practical skills and knowledge.
Example: "To find an element in the middle of a singly list, I would do so in O(n) time and O(1) space. To start, I count how many nodes there are on the list. If, for example, I have five nodes on the list, the middle element will be the third one. If I have an even number of elements, I'll divide that number by two. In a list of four nodes, the second element will be the one in the middle."
How would you know if a linked list is a circular list?
This question determines whether you can apply your knowledge about coding to differentiate between lists.
Example: "There's a simple way to know whether my linked list is circular. Simply put, a circular list will have all of its nodes connected to make a circle and will not be marked as NULL-terminated."
Questions about string coding
String coding is asked in the majority of programming interviews you'll be part of. To answer questions about string coding properly, you should first know about arrays. String arrays represent text and are made up of several characters, numbers, and spaces. A string could say anything from "I've worked in three different disciplines" to "I ate a sandwich yesterday."
Like arrays, string coding is seen in multiple programming languages. Your responses allow the interviewer to see how you interpret problems involving string coding across multiple languages.
Here's a list of some questions you may be asked about string coding:
How do you know if there are duplicates in your string?
This is a practical question that tells the interviewer whether you can articulate complex code.
Example: "There are a few steps in finding out whether there are duplicates in your string. First, I would turn my string into a character array. Next, I'll need to iterate the array. A character should be used as a map key to see if a character has been used before. I'll know if there are no duplicates because the map key won't exist.
If I notice that a map key does exist, I'll need to increment the counter. These steps should be repeated until every character in the string has been iterated. If I do not have any map keys across the string, it means that there are no duplicates."
What are anagrams in strings?
This question tests your theoretical knowledge and your ability to articulate terms and concepts.
Example: "A string can be an anagram of another if the two share similar characters in a different order. For example, a string that has the characters erty and ytre are anagrams of each other."
Questions about binary trees
Questions about binary trees are common in interviews for programmers.
Interviewers will ask you about binary trees because they want to make sure you have a clear understanding of the structures on which code is built. Here are some examples of questions you may be asked about binary trees.
How can you search a binary tree for specific elements?
An interviewer would ask this to determine your general knowledge.
Example: "To search a binary tree for specific elements, I would search from the tree's root node."
Can you traverse a specific binary tree without recursion?
Here, the interviewer is looking for your knowledge on the technicalities of recursion and whether you truly understand it.
Example: "The short answer to this question is yes, you can. If you plan to do so, you should use stack."
Related: Top Python Interview Questions
Explore more articles
- 7 Important Departments in HR (With Detailed Explanations)
- How to Give Negative Feedback at Work (With Tips and Examples)
- 12 Types of Construction Drawings (With Definition)
- Differences Between Accounts Receivable vs. Accounts Payable
- What Are Contract Jobs? With Tips, Challenges, and Benefits
- Guide to Esthetician Skills: Definition and Examples
- Functional Organization Structure: Pros and Cons
- Technical Requirements (With Definitions and Examples)
- Tools of Project Management You Can Use as a Project Manager
- 10 Mission Statement Examples (Plus Importance and Tips)
- 10 Qualities That Can Help You Become a Successful Leader
- How to Write a Topic Sentence (With Examples and Tips)