Live Coding

Live coding is an exercise in which a programmer solves a coding problem in a brief period of time, either on a whiteboard or in a code editor. It is sometimes used in technical job interviews to gauge a candidate’s programming skill.

Live coding is definitely not the only technique used by employers in job interviews, but it is used often enough that you should be prepared for it. You can have a great job interview but lose out on getting hired due to poor performance in a live coding session.

We will watch a live coding demo and then review the process in detail. Then, you’ll get some practice on your own.

Live Coding Demo

In the ideal live coding session, the programmer follows these steps:

  1. Gather Requirements
  2. Break Problem Down
  3. Pseudocode
  4. Write Syntax
  5. Test
  6. Make Changes

Watch our live coding demo to see how each of these steps plays out. Then come back here to review the steps in detail.

Live Coding Playbook

Now let’s review each of the steps in detail.

Gather Requirements

In the video, the interviewer provided requirements that were intentionally vague. The first thing the candidate had to do was to gather additional requirements to have a strong understanding of the problem.

This is required communication on the candidate’s behalf. You should go as far as to talk through the given input, and create an output. This provides an opportunity for the interviewer to verify the candidate’s understanding and correct them if it is incorrect. This avoids the situation in which the candidate starts solving the problem, only to realize that they are not solving the exact problem that was provided

Break Down the Problem

After successfully gathering the requirements, the candidate broke the problem down into two separate pieces. You should identify what needs to be done first, and what needs to be done next.

Breaking the problem down gives the candidate the opportunity to focus on one aspect of the problem at a time.

Pseudocode

Once the candidate has a hold on the separte pieces of their intended solution, they can begin working on the logic of the problem.

For the first chunk of their proposed solution the candidate wrote, “Loop over input, remove vowels.”

For the second chunk of their proposed solution, the candidate wrote “Loop over vowel-less str, remove odd index chars.

Psuedocoding the problem promotes communication around the proposed solution. It is a way to share thoughts with the interviewer without starting to code. It also provides a structure for the solution that you are about to code.

Write Syntax

Now that we have a plan, and a map drawn out in the form of our pseudocode we can start coding!

You’ll notice the candidate is talking through their actions as they write code down. This shows the candidate has the ability to communicate effectively with another developer.

As you write syntax you may find that you still don’t have all of the requirements. In this video the interviewee did not know if the letter ‘y’ was considered a vowel. To overcome this confusion they simply asked the interviewer for more clarity on the requirements!

While writing their code, occasionally the candidate would realize they didn’t declare a variable before, or forgot to include something above their already written code. That is okay! You want to show the interviewer your problem solving process, and very rarely will you write something perfect from top to bottom. Don’t hesitate adding new lines above your already written solution if you need to declare more variables!

Test

After the candidate finishes the first version of their solution they need to test it! As programmers, we don’t usually get the right answer on the first try, and without a debugger to point us in the correct direction, we are left to walking through a test case ourselves.

You’ll notice the candidate keeps track of the variables throughout the entire program, by writing them on the board, and updating them as they walk through the program line by line.

At the end of the program, the candidate can compare their produced answer and compare it to the answer that was agreed upon when they gathered the requirements of this problem.

Make Changes

When testing your solution, you will more than likely find that you made a mistake. It may be a small mistake, or it may be a big mistake. Making a mistake can be a great thing in a live coding session. Take a step back, and try to figure out where the mistake is happening. This is usually very apparent in the testing phase, if you test line by line, you should see when mistakes happen, when they occur in your code.

You want to show the interviewer you have strong problem solving skills, and part of problem solving is being able to figure out mistakes you have made in your own solution, and then fixing them.

If you find a mistake in your solution, great! Fix the mistake, and test your solution again.

Live Coding Practice

You will have the opportunity to practice live coding with a mentor and get feedback. Before doing so, you should also practice on your own so you can get used to the process. We have provided a few practice problems below.

To make the most of this practice, you need to practice in the same format you will be tested. To do that, you need to emulate a live coding session. After you read the problem, step away from your computer and work through a solution using a piece of paper or a white-board. Talk through your ideas and solution. Don’t forget to hand-test your solution before typing it into your computer.

Practice Problems

Note

If you have not signed up for a HackerRank profile yet, you will need to do so in order to do these problems. After creating an account and logging into HackerRank, please come back here and follow the links to the prep work problems.

  1. Staircase
  2. camelCase
  3. Grading Students
  4. Mars Exploration

Practice Problem Solutions

We provided solutions for all four of the problems to use to verify your work, or if you get super stuck. The first two solutions have a break down of the steps you should follow. If you are struggling with this prep work, start with the solution to the Staircase problem.

Note

Solutions are provided in Python, since it is the most common language across LaunchCode courses. It is also relatively easy to read, even if you don’t know much Python. If you have language-specific questions about your solution, ask a instructor/TA/mentor.

Further Practice

There are several free sites where you can practice the types of problems that are often used in live coding exercises. Find one that you like, and practice some additional problems.

Solving these problems in the cozy confines of a web interface or code editor is definitely different from solving them on a whiteboard, but you’ll still build some problem-solving muscle by working with these sites.