LiveCoding... It's like one of those hardcore exams where you have to solve a problem on the spot in front of an audience of strangers. Or, like improvising on stage – just the thought of it can be terrifying! Yet, some people actually thrive on it. And for those who don’t, well, it’s all about learning to take the hit. Like everything else in this world, acing LiveCoding comes with practice.

What is LiveCoding?

It's solving a programming task live, to see how you code under pressure and, basically, how you code in general. This can happen either in the office or at home during a call. If you're at home, you'll likely be asked to join an online platform and code live. In the office, someone might just stand next to you. Sounds a bit scary, doesn't it? However, the tasks given during live coding are usually simpler than those in a test assignment. Most companies prefer one over the other, but our job is to be prepared for both.

Sometimes, you might get a mix of a test assignment at the office and LiveCoding. For instance, you're given a task divided into sprints. You're asked what you'd do, given an hour to work on it, then they review what you've done, discuss the code, give you the next part, and so on.

Where to Code During LiveCoding?

  • In-Person: You might be given a computer with an IDE or asked to write solutions on paper or in Google Docs. Be ready for anything.
  • Remote: Either you share your screen and show off your skills in your configured IDE, or you might be asked to use an online IDE like Codility.

The LiveCoding Algorithm

LiveCoding can be remote (sharing your screen) or in-person. Imagine this: you're given a problem, a computer turns on, someone stands behind you (or connects to your screen), and you start typing code with trembling fingers… Wait, don't rush it. First, stop and understand the task.

Understand the Task

First, make sure you fully understand the task. Ask clarifying questions to confirm your understanding. There's always someone there to answer your valid queries.

Think About the Best Solution

Consider various solutions, not just one. Evaluate the time and space complexity of each and choose the most optimal one that you can implement quickly and efficiently. Verbalize your thought process. Even if something goes wrong due to nerves, at least it's clear that you started off on the right track.

Start Coding!

As you write your code, try to adhere to the principles of SOLID/KISS/DRY. Make sure to explain each line of code – sometimes, you might even get helpful hints through leading questions.

Create a Unit Test for Your Solution

It's way cooler than just using System.out.println. But you already knew that, right?

Don't Forget During LiveCoding:

Talk out loud! LiveCoding is 50% coding and 50% verbalizing your thoughts. Usually nobody’s trying to fail you; interviewers assess you. If they see that you're thinking the right way but veering off track, they're likely to help and steer you right.

If you're writing subpar code due to time constraints, say so. Then the interviewer knows you don't usually cram everything into one giant Main method; you're just pressed for time. Similarly, if you can't come up with proper names for classes or variables, it's better to mention it.

The goal during an interview is to write code quickly. Still, try to write it well, up to industry standards, not just academic ones. Write well what you can, and discuss what you can't with the interviewers.

For reference, check the official Oracle document: Oracle Java Naming Conventions

Always consider edge cases (especially in algorithmic problems), validations, and performance.

Don't test your code by running the application. Use unit tests whenever possible.

Examples of LiveCoding Tasks

There can be many and varied. But the examples below give a general direction. Usually, these are academic problems that you've encountered in your studies.

Simple Tasks

These are often asked to be written in a doc file or even on a piece of paper.

Examples include:

  • Reversing an array (Input: [1,4,3,9,0], Output: [0,9,3,4,1])
  • Calculating factorial (iteratively or recursively)
  • Checking if one word can be formed from another
  • Programming a chessboard

Tasks on Online Platforms like Codility

Such as algorithm tasks (binary search, sorting algorithms) or using the Streams API

Complex Tasks During an Office Visit

Probably the most stressful variant. Here, it could be anything, like programming a chessboard or writing a financial manager by sprints.

Things to Think About Before LiveCoding (and Before a Test)

  • How to test code with random values
  • How the program should behave when an external system is unavailable (e.g., accessing GitHub when it's down)
  • Think about the "Command" pattern and how to apply it.

Tips:

  • Prepare a Gradle or Maven project in advance.
  • Use IntelliJ IDEA shortcuts. Here are a couple of articles on the topic:

Platforms for Practice

  • Codility: Look for a course on basic algorithms. Focus on iterations and arrays, sorting, binary search, and stacks and queues.
  • Leetcode Study Plans: There are many tasks here, but you don't need to solve them all. Use their Study Plan to solve a certain number of tasks each day. The most interesting is LeetCode75, which consists of 75 essential problems for acing LiveCoding.
  • Codeforces: An interesting resource with explanations and good solutions for each problem. If you can't solve a problem, check the solution, then try to solve it again on your own.

Preparation Plan

  • Use the preparation platforms mentioned above.
  • Watch examples of LiveCoding on YouTube.
  • Solve one task every couple of days.
  • Verbalize your thought process while solving.
  • Record yourself solving every tenth task, then review for mistakes.
  • Always rework the tasks after solving.
  • Sometimes, you may be asked to solve a simple task "on a sheet" (either a real paper or in Google Docs). It can be challenging as we’re used to syntax highlighting and auto-correction. Make sure to practice this exercise every few days.

Trust us, if you put in the effort, you'll thank yourself during the real LiveCoding session!