Programming Interview Questions: What to Be Ready For, And Three Examples to Study

programminginterviewquestionsNo matter what language or position you’re applying to work with, programming interviews are tough, and take a lot of preparation and research before hand in order to ace.

Even if you’re good at what you do, interviewers want to know that you’re someone who’s ready to solve complex problems at a moment’s notice. They want someone who works well under pressure, who can provide solutions in an organized and timely fashion, and who’s able to verbally and visually clarify their thought process so the interviewer understands how they work through problems.

There’s a handy course here about how to land an interview, but once you have that part down, it’s on to the actual process! This guide will help you prepare for some of the most common programming interview questions, and other tips to be aware of before stepping into that office.

Things to Know Before the Interview

1. Ask a lot of questions. This might not seem like a good idea at first, but it’s very important that you understand exactly what the interviewer is asking of you before you dive into a code example.

Interviewers know the problems they give you are hard, and they’re not expecting you to have the answer right away. So, take your time, ask a couple clarifying questions, and make sure you know what it is they want from you. Interviewers would much rather see that you’re a meticulous, retentive, and methodical person, than someone who wants to rush to a solution seemingly unprepared.

2. Be honest with what you do and don’t know. If you’re asked a question that you’ve heard before, let the interviewer know before attempting to solve it. This is just basic honesty, and is a good way to demonstrate to the interviewer your ability to cooperate with others as a person, and not just a qualified coder. It also gives them the chance to ask an extra question if they feel that one was too easy for you.

Similarly, if you don’t know something, let the interviewer know that you’re unfamiliar with the concept, but you will try your best to work through it. You’ll look worse trying to pretend as if you know what you’re doing, than you would admitting a particular challenge is new to you, and then applying the knowledge you do have to work it out anyway. Even if you don’t get it right, the interviewer will appreciate the approach.

3. Practice writing on a whiteboard. This should be a no-brainer for most programmers. Most programming interview sessions will have a whiteboard present, and the interviewer will ask you to work out problems with illustrations, diagrams, and code examples. Show all of your work, even if you think it’s something obvious. This will help you visualize the challenge better, and allows the interviewer to observe your thought process, which is a major part of what they’re testing you for.

You can also use the whiteboard to write code examples, but make sure your handwriting is neat and organized. Sloppy visuals and rushed handwriting will give a bad impression.

Example Questions

While the tips above are important for making a good impression overall, the technical questions are the bulk of a programming interview, and will make or break your chances!

Here are three common challenges you should be prepared for.

1. Reversing a linked list

Data structure manipulation is one of the most common concepts you can be asked about during a programming interview. Reversing a linked list is such a common problem, that knowing how to do it should be expected of you.

It’s particularly vital that you understand exactly what is going on in this function, rather than just memorizing how to do it. You can learn about this in more detail in this beginner’s programming class for Java, which the following example is written in.

public static Node reverse(Node head)
    // Checks if our Linked list is length 0 or 1.
    if(head == null || head.nextNode == null)
        return head;
    Node curr = head;
    Node next = head.nextNode;
    Node prev = null;

    // While our next node is not null,
    // keep reversing the next references of each
    // of Linked List's Nodes.
    while(next != null) 
        curr.nextNode = prev;
        prev = curr;
        curr = next;
        next = next.nextNode;
    // Reassign head as the current node.
    head = curr;
    head.nextNode = prev;

    return head;

2. Calculating a factorial

This is a simple math function, done both iteratively and recursively. You may be asked to write a function using one or both of these methods, so be prepared. It also helps to understand how iteration and recursion works, which you can learn in this course on the structure and interpretation of computer science.


public static int factorial_iterative(int num)
    if ( num < 0 )
        System.out.println("Factorial must be a positive integer.");
        return 0;

    // Start at 1 since we're multiplying, not adding
    int fact = 1;

    // Loop from 1-num and multiply each time to fact
    for (int i = 1; i <= num; i++)
        fact = fact*i;

    return fact;


public static int factorial_recursive(int num)
    if ( num < 0 )
        System.out.println("Factorial must be a positive integer.");
        return 0;

    // Return 1 once the factorial has bottomed out
    if (num == 1)
        return 1;
    // Otherwise, return num * factorial of num - 1
    return num * factorial_recursive(num - 1);

3. What’s the difference between overriding and overloading a function?

Function overloading refers to when there is more than one function with the same name and functionality, in the same class, but each with different parameters.

For example, say you’re a game developer coding a function for the player entity to take damage. In your game, there are numerous ways the character can take damage – from falling, from getting attacked by an enemy, from getting squished by a boulder, etc. You would have several functions, all named damage, but each with different parameters to calculate specific types of damage. By overloading, you’re able to use the same name for numerous functions that take in different parameters.

Function overriding refers to two functions that share the same parameters, but where a function in the child class redefines or sometimes extends a function in the parent class.

Going back to the game development example – say you have a parent class called Gun, and within that class are numerous child classes, each for a different gun. The parent class Gun has a function called Gun.shoot(). The child classes each have their own functions for shooting as well – Rifle.shoot(), Pistol.shoot(), Shotgun.shoot(). By overriding Gun.shoot(), you’re able to define the shoot function uniquely for each child class.

You can learn more about function overloading and overriding in this lecture, part of a course on learning Java the easy way.

Trying to prepare for a specific language-based programming interview?

You may also want to read: