Coding tests have been the backbone of technical hiring for decades. If you’re a web developer, programmer, or engineer on the job market, your ability to demonstrate your skills in a coding interview is critical to landing your next role.
The key to succeeding in these interviews is preparing well for the styles of problems you might encounter. In this post, we’ll break down four categories of coding interview questions you could face — and 22 sample questions to help you start preparing.
Coding interview questions — sometimes called coding challenges — ask developers to write code to find an answer to a problem. Depending on the role and company, coding questions can be language-specific or allow developers to respond in their coding language of choice. Often, these questions are asked directly via an in-browser IDE that provides developers with the tools they need to provide a solution in full.
While coding questions come in a variety of formats, the strategies for answering them are similar. As you write your code, you’ll be expected to explain your solution to the hiring team. They’ll typically give you real-time feedback on the efficacy, complexity, and accuracy of your solution.
It’s important to keep in mind that a “correct” answer isn’t always enough to pass a coding interview. That’s because the approach also allows hiring teams to assess your technical communication, your code quality, and the efficiency of the solution.
Examples of coding tests include:
This part of the process is highly variable, with hiring managers able to choose from a number of formats on how to evaluate technical skills. Programmers will need to carefully prepare to ensure they can adapt to a variety of challenges.
There are a number of different types of coding questions employers can use to evaluate a programmer’s coding skills. The difficulty and composition of these tests will vary based on the experience-level of the role.
Generally, the more experienced a developer is, the more ambiguous and challenging the questions they will be asked. For example, candidates for entry-level roles might complete coding questions that test execution of predefined problems. In contrast, questions for senior roles can become more open-ended, writing code for problems without predefined solutions.
The following is a list of the types of coding questions a programmer might encounter during a technical interview.
Algorithm questions are foundational to the technical interview. They test a candidate’s coding skills and ability to solve problems with algorithms in a programming language of their choice.
Sample Question: The Efficient Janitor
The janitor of a high school is extremely efficient. By the end of each day, all of the school’s waste is in plastic bags weighing between 1.01 pounds and 3.00 pounds. All plastic bags are then taken to the trash bins outside. One trip is described as selecting a number of bags which together do not weigh more than 3.00 pounds, dumping them in the outside trash can and returning to the school. Given the number of plastic bags, and the weights of each bag, determine the minimum number of trips the janitor has to make.
This problem tests the candidate’s ability to use two pointers to search for pairs in an assorted array.
More algorithm coding questions:
Data structures are a fundamental concept of computer science and any programming language. Essential for algorithmic design, programmers use data structures for the efficient organization and modification of data.
Sample Question: Binary Search Tree
You are given a pointer to the root of a binary search tree and values to be inserted into the tree. Insert the values into their appropriate position in the binary search tree and return the root of the updated binary tree. You just have to complete the function.
A binary search tree is a rooted binary tree data structure with internal nodes that each store a key less than all the keys in its right subtree and greater than all the keys in the node’s left subtree.
This question tests a programmer’s ability to work with data structures to solve problems.
More data structure questions:
An array is a data structure containing elements identified by one or more indexes or keys. Arrays are a fundamental data structure, making them a favorite of interviewers looking to test programmers coding skill. Because the size of an array can’t change, solving this style of question requires finding the optimal way to either rearrange or copy the array into the correct result.
Sample Question: Automated Cutting Machine
An automated cutting machine is used to cut rods into segments. The cutting machine can only hold a rod of minLength or more. A rod is marked with the necessary cuts and their lengths are given as an array in the order they are marked. Determine if it is possible to plan the cuts so the last cut is from a rod at least minLength units long.
This problem tests a programmer’s ability to use arrays, along with loops and greedy algorithms. It requires the programmer to come up with an algorithm to check if an array of given lengths of the rod can be cut from left and right exactly n – 1 time and the remaining size of the rod is at least minLength in a constrained time and space complexity.
More array coding questions:
Most coding questions aren’t specific to a particular programming language, allowing a programmer to write code in their language of choice. However, some coding interviews will have questions that test a specific language required by the role.
Sample Question: Enhanced Flexible Grid
Languages: JavaScript, CSS
Create a flexible grid with 1 row and 4 columns. The width of each column is 25% of the window size. This percentage width must be maintained even if the page is resized. Each cell of the grid can contain another 1×4 flexible grid. The border of the grid must be 1px black.
Perform the following operations based on the value of window size:
This question tests a developer’s ability to write code in JS and CSS and build UI elements. Essential to responsive design, a flexible grid tests a candidate’s ability to perform a task required by a role in front-end development.
More language-specific coding questions:
15 Common Problem-Solving Interview Questions
Software Engineering Questions to Know in 2022
7 System Design Interview Questions Every Software Engineer Should Know
What Does a Software Developer Do? Role Overview and Skill Expectations