Skip to lesson

Live Coding on a Shared Screen in Online Interviews

In an online round you solve the problem while the interviewer watches your screen, and a frozen setup or a silent panic costs as much as a wrong answer. They are checking for a calm routine: ready tools, small runnable steps and clear talk when something breaks.

Before the call: setup checklist and a blank template

A live-coding round is an online interview where you solve a problem while the interviewer watches your screen, in a shared editor or in your own IDE.

Prepare the machine the day before, not five minutes before. Check that Java runs and a blank Main.java compiles and prints, and keep that template open so you never start from an empty screen.

Terminal
java -versionjavac Main.javajava Main
  1. Run java -version and compile a test file; know which Java version you have.
  2. Increase the editor font to 16–18 pt and use a light or high-contrast theme; it is easier to read over video.
  3. Turn off notifications (Focus Assist on Windows, Do Not Disturb on macOS); close chats, mail and extra browser tabs.
  4. Test camera, microphone and headphones in the meeting tool; sit facing a light, not a window.
  5. Plug in the laptop, keep a mobile hotspot ready as internet backup, and save the recruiter's phone number or email.
  6. Open your blank Main.java template with a test helper, and a scratch notes file for examples.

Example 1 · A blank Main.java template that runs from the first minute

Main.javaJava
import java.util.*;
public class Main {    // Problem: (paste or summarise the question here)    // Examples: (write the agreed inputs and outputs here)    static int solve(int[] nums) {        return 0;   // replace with the real solution    }
    static void check(String name, Object expected, Object actual) {        boolean ok = Objects.equals(expected, actual);        System.out.println((ok ? "PASS " : "FAIL ") + name + ": expected " + expected + ", got " + actual);    }
    public static void main(String[] args) {        check("example 1", 0, solve(new int[] {}));        System.out.println("template ready");    }}
Output
PASS example 1: expected 0, got 0
template ready

What this code does

  • The template compiles and prints before you write any logic, so the first run of the round succeeds and proves your setup works.
  • import java.util.*; saves time during the round, and the check helper prints PASS or FAIL with both values for every test you add.

Shared editors vs sharing your own IDE

A shared editor is a browser coding pad that both you and the interviewer can see and type in, often with no autocomplete.

Browser pads and your own IDE behave differently. Example 2 is a template that works whether or not the pad feeds standard input.

Example 2 · A template that works with standard input or without it

Main.javaJava
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import java.util.HashMap;import java.util.Map;
public class Main {    static int[] twoSum(int[] nums, int target) {        Map<Integer, Integer> seen = new HashMap<>();        for (int i = 0; i < nums.length; i++) {            Integer j = seen.get(target - nums[i]);            if (j != null) return new int[] {j, i};            seen.put(nums[i], i);        }        return new int[0];    }
    public static void main(String[] args) throws IOException {        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));        String numbersLine = in.readLine();        String targetLine = in.readLine();        if (numbersLine == null || targetLine == null) {   // no input given: use our own sample            numbersLine = "2 7 11 15";            targetLine = "9";        }        int[] nums = Arrays.stream(numbersLine.trim().split("\\s+")).mapToInt(Integer::parseInt).toArray();        int target = Integer.parseInt(targetLine.trim());        System.out.println(Arrays.toString(twoSum(nums, target)));    }}
Output
[0, 1]

What this code does

  • If the editor feeds input, the program reads two lines from standard input; if not, it falls back to a sample, so it never crashes on empty input.
  • Keeping the solution in its own method (twoSum) means you can switch between pad-style input and plain test calls without touching the logic.

Pads such as CoderPad, HackerRank CodePair or even a Google Doc may or may not run code, may fix the class name (often Main or Solution), and may give input on standard input or expect you to call the method yourself. A Google Doc cannot run anything, so treat it like a whiteboard. When you share your own IDE you get autocomplete and the debugger, but you must share only that window and keep the font large.

Ask these setup questions in the first minute:

  • "Can I run the code here? Which Java version?"
  • "Should I read input from standard input, or call the method from main?"
  • "Is the class name fixed? Can I use the standard library, like java.util?"
  • "Do you prefer I share my own IDE or use this editor?"

Step by step during the round

A debug print is a temporary println of variables that shows what the code is really doing; remove it or switch it off before you say you are done.

Small runnable pieces beat one big attempt. Example 3 builds a first-unique-character solution step by step, running after each one, with a DEBUG flag for the extra prints.

Example 3 · Building in small runnable pieces

Main.javaJava
import java.util.LinkedHashMap;import java.util.Map;
public class Main {    static final boolean DEBUG = true;
    // Step 1 (run after writing it): count each character, in first-seen order    static Map<Character, Integer> counts(String s) {        Map<Character, Integer> m = new LinkedHashMap<>();        for (char c : s.toCharArray()) {            m.merge(c, 1, Integer::sum);        }        return m;    }
    // Step 2 (run again): first character with count 1, or '_' if none    static char firstUnique(String s) {        Map<Character, Integer> m = counts(s);        if (DEBUG) System.out.println("  debug counts for " + s + ": " + m);        for (Map.Entry<Character, Integer> e : m.entrySet()) {            if (e.getValue() == 1) return e.getKey();        }        return '_';    }
    // Step 3: test calls, including edge cases    public static void main(String[] args) {        System.out.println("swiss -> " + firstUnique("swiss") + " (expected w)");        System.out.println("aabb -> " + firstUnique("aabb") + " (expected _)");        System.out.println("empty -> " + firstUnique("") + " (expected _)");    }}
Output
  debug counts for swiss: {s=3, w=1, i=1}
swiss -> w (expected w)
  debug counts for aabb: {a=2, b=2}
aabb -> _ (expected _)
  debug counts for : {}
empty -> _ (expected _)

What this code does

  • Each step was run before moving on: first the counting map, then the answer, then the edge-case calls. A mistake shows up right after the step that caused it.
  • The DEBUG flag keeps the extra print lines easy to switch off before you say you are done.

Work in small, runnable pieces and keep talking in short sentences:

  • Confirm the problem, input format and two examples; write them as comments.
  • Say the brute force and your approach with complexity; get a nod.
  • Type the signature and one test call; run it (it should compile and print something).
  • Fill in the logic in small steps, running after each one.
  • Add edge-case test calls; run all of them.
  • State the final complexity and any trade-offs.

Put your own test inputs in main, including the edge cases you listed, and print expected next to actual so both of you can see the result at a glance.

Predict the output

Run it before you trust it

A quick test call decides whether the next step is safe. Predict what each run prints.

Round 1 of 2

What does this test call print?

int[] nums = {-4, -2, -9};
int best = 0;
for (int n : nums) {
best = Math.max(best, n);
}
System.out.println(best);

When it breaks: errors, debugging and asking for a hint

A stack trace is the list of method calls printed with a runtime error; the first line that points into your own code is where to look.

Errors are information, not failure. Example 4 catches an index error, reads the message aloud as you would in the round, and fixes the loop bound.

Example 4 · Reading a runtime error and fixing it aloud

Main.javaJava
public class Main {    // Buggy version: the loop bound reads one element past the end.    static int sumBuggy(int[] a) {        int sum = 0;        for (int i = 0; i <= a.length; i++) {            sum += a[i];        }        return sum;    }
    static int sum(int[] a) {        int sum = 0;        for (int i = 0; i < a.length; i++) {            sum += a[i];        }        return sum;    }
    public static void main(String[] args) {        int[] fees = {1200, 800, 500, 300, 200};        try {            sumBuggy(fees);        } catch (ArrayIndexOutOfBoundsException e) {            System.out.println("Error: " + e.getClass().getSimpleName() + ": " + e.getMessage());            System.out.println("Reading it aloud: index 5 does not exist in an array of 5, so my loop goes one step too far.");        }        System.out.println("Fixed with i < a.length: " + sum(fees));    }}
Output
Error: ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
Reading it aloud: index 5 does not exist in an array of 5, so my loop goes one step too far.
Fixed with i < a.length: 3000

What this code does

  • Since Java 11, the message names both the bad index and the length, which points straight at an off-by-one loop bound.
  • In a real round you would see a stack trace instead of a catch; the first line that mentions your own method and line number is where to look.

Read errors aloud, top to bottom. "cannot find symbol" means a misspelt name or a missing import, "incompatible types" a wrong type, "missing return statement" a path with no return, "';' expected" a typo. A runtime error gives the exception and a stack trace.

Debug calmly with a print statement just before the failing line, rerun, and compare with what you expected. If you are stuck for more than two or three minutes, ask a focused question: "I think the window should shrink when a character repeats, but I am unsure how to track the last position; am I on the right track?"

Fix the error

Read the error, fix the line

Read the compiler message aloud, then pick the replacement for the highlighted line.

Round 1 of 2

Add up the marks.

int total = 0;
for (int m : marks) {
totl += m;
}

Error

error: cannot find symbol
  symbol:   variable totl
  location: class Main
Remove or comment out debug prints before you say "done", or keep them behind a DEBUG flag.

Etiquette, proctoring and connection problems

Proctoring is the monitoring of an online round: recording, tab-switch or paste detection and camera checks.

Be visible and honest. Keep the camera on, share only the editor window or the browser tab you were asked to share, and do not paste code from outside sources or use AI assistants unless the interviewer explicitly allows it. Many platforms record the session or flag large pastes and tab switches. If you need to look up an API, ask first: "May I check the Javadoc for TreeMap.floorKey?"

If the connection drops, rejoin straight away through the same link, and if that fails, switch to the hotspot and message the recruiter with the time it happened. Save your code locally or copy it into your notes regularly, so a crash never costs you the solution.

  • Share one window, not the whole desktop; close personal tabs first.
  • No outside code, no AI tools, no second person in the room, unless allowed.
  • Look at the camera when speaking; mute while typing loudly only if asked.
  • Connection drop: rejoin, switch network, message the recruiter, paste back your saved code.

Order of execution

The connection drops

Twenty minutes in, the call ends. Put the recovery steps in order.

Next step

Check your understanding

12 quick questions