Skip to lesson

Challenges You Solved and Did-You-Build-It Questions

After the pitch comes the question that separates a project you built from one you copied: "tell me about a challenge", then "show me where that happens". The interviewer is checking that you can tell a clear story and that you know your own code.

STAR for a technical challenge

STAR is a four-part story format: Situation, Task, Action, Result. Situation sets the scene, Task says what had to be solved, Action says what you did, and Result gives the outcome with a number or a test.

Example 1 is a full STAR story about two buyers getting the last item. Example 2 shows the bug and its fix in a few lines of Java you could sketch on a whiteboard.

A STAR story for a technical challenge has four parts. Situation, about 10 seconds: one sentence of context. Task, about 10 seconds: what had to be solved and why. Action, about 40 seconds, half the story: what you did, naming the tool or idea. Result, about 10 seconds: a number or a test.

Example 1 · A STAR story: two buyers, one item

Text
SITUATION  In ShopLite, the order endpoint read a product's stock, checked it,           then saved the new value in a separate step.TASK       In a test with parallel requests, two buyers both got the last           notebook. Stock must never be oversold.ACTION     I reproduced it with a test that sends 20 parallel orders for           1 unit. The cause was check-then-act: both requests read stock = 1           before either wrote. I made the check and the update one locked           step: the service loads the product with a row lock           (SELECT ... FOR UPDATE) inside the order transaction.RESULT     The same test now gives exactly 1 order and 19 "409 out of stock"           answers, every run. I kept the test so the bug cannot come back.
Time split
Situation 10 s · Task 10 s · Action 40 s · Result 10 s

What this code does

  • The action names the cause (check-then-act) and the tool (a row lock), the two things a follow-up will ask about.
  • The result is a repeatable test with exact numbers, not "it worked better".
  • Keeping the test as a guard is a small detail that shows good engineering habits.

Example 2 · The oversell bug and the fix in plain Java

OversellDemo.javaJava
class Stock {    private int units;
    Stock(int units) {        this.units = units;    }
    int read() {        return units;    }
    void write(int units) {        this.units = units;    }
    synchronized boolean tryReduce(int quantity) {        if (quantity <= units) {            units -= quantity;            return true;        }        return false;    }}
public class OversellDemo {    public static void main(String[] args) {        Stock stock = new Stock(1);        int seenByA = stock.read();        int seenByB = stock.read();        int orders = 0;        if (seenByA >= 1) {            stock.write(seenByA - 1);            orders++;        }        if (seenByB >= 1) {            stock.write(seenByB - 1);            orders++;        }        System.out.println("Check then act, both read first: orders = " + orders + ", stock = " + stock.read());
        Stock fixed = new Stock(1);        boolean a = fixed.tryReduce(1);        boolean b = fixed.tryReduce(1);        System.out.println("One locked step: A = " + a + ", B = " + b + ", stock = " + fixed.read());    }}
Output
Check then act, both read first: orders = 2, stock = 0
One locked step: A = true, B = false, stock = 0

What this code does

  • The first half replays the bad timing by hand: both requests read 1 before either writes, so two orders succeed for one unit and the stock still looks correct.
  • tryReduce makes check and update one synchronized step, so only one caller can pass the check.
  • In the database the same idea is a row lock (SELECT ... FOR UPDATE) or one conditional update: UPDATE products SET stock = stock - ? WHERE id = ? AND stock >= ?, then check the affected row count.

Give the Action about half the time and name the tool or idea you used (a row lock, an index, equals instead of ==), because that is what the interviewer asks about next. A good technical story takes 60 to 90 seconds.

End with a result you can show: a number or a test, plus what you kept doing afterwards. Revise: Check-then-act bugs (opens in a new tab).

Order of execution

Order a STAR story

Put these sentences in STAR order: Situation, Task, Action, Result.

Three stories to prepare: a bug, a performance fix, a design change

A story bank is a small set of prepared STAR stories that you adapt to the question: a bug, a performance fix and a design change.

Example 3 is the evidence for a bug story: an owner check that failed only for customer ids above 127. Example 4 counts queries before and after fixing an N+1 problem.

Example 3 · A bug story: the owner check that failed above 127

OwnerCheckBugDemo.javaJava
import java.util.Objects;
public class OwnerCheckBugDemo {    static boolean isOwnerBuggy(Integer orderCustomerId, Integer loggedInId) {        return orderCustomerId == loggedInId;    }
    static boolean isOwnerFixed(Integer orderCustomerId, Integer loggedInId) {        return Objects.equals(orderCustomerId, loggedInId);    }
    public static void main(String[] args) {        for (int id : new int[] {42, 127, 128, 500}) {            Integer fromOrder = Integer.valueOf(id);            Integer fromToken = Integer.valueOf(id);            System.out.println("customer " + id + ": buggy = " + isOwnerBuggy(fromOrder, fromToken)                    + ", fixed = " + isOwnerFixed(fromOrder, fromToken));        }    }}
Output
customer 42: buggy = true, fixed = true
customer 127: buggy = true, fixed = true
customer 128: buggy = false, fixed = true
customer 500: buggy = false, fixed = true

What this code does

  • == on two Integer objects compares references. Integer.valueOf reuses cached objects only from -128 to 127 by default, so small ids pass and larger ids fail.
  • This makes a great bug story: the symptom ("403 only for newer customers"), the root cause (reference comparison), the fix (Objects.equals, which is also null-safe).
  • Section 23's Core Java Questions module covers the wrapper cache; here it is the evidence behind a story.

Example 4 · A performance story: counting the N+1 queries

NPlusOneDemo.javaJava
import java.util.LinkedHashMap;import java.util.List;import java.util.Map;
class FakeOrderDb {    int queries = 0;
    List<Integer> findOrderIds() {        queries++;        return List.of(101, 102, 103, 104, 105, 106, 107, 108, 109, 110);    }
    int countItems(int orderId) {        queries++;        return orderId % 3 + 1;    }
    Map<Integer, Integer> countItemsForAll(List<Integer> orderIds) {        queries++;        Map<Integer, Integer> counts = new LinkedHashMap<>();        for (int id : orderIds) {            counts.put(id, id % 3 + 1);        }        return counts;    }}
public class NPlusOneDemo {    public static void main(String[] args) {        FakeOrderDb before = new FakeOrderDb();        int itemsBefore = 0;        for (int id : before.findOrderIds()) {            itemsBefore += before.countItems(id);        }        System.out.println("Before: " + before.queries + " queries, " + itemsBefore + " items");
        FakeOrderDb after = new FakeOrderDb();        int itemsAfter = 0;        for (int count : after.countItemsForAll(after.findOrderIds()).values()) {            itemsAfter += count;        }        System.out.println("After:  " + after.queries + " queries, " + itemsAfter + " items");    }}
Output
Before: 11 queries, 21 items
After:  2 queries, 21 items

What this code does

  • The "before" loop runs 1 query for the list plus 1 per order: 1 + N queries, the N+1 problem.
  • The "after" version loads the items for all orders in one query (in JPA, a JOIN FETCH or an IN query), and the answer is the same.
  • The story's result line comes straight from this: "11 queries became 2, with the same data".

Prepare stories from your real project: invented ones fall apart at the second follow-up question.

  • Bug story: symptom, how you reproduced it, root cause, fix, test.
  • Performance story: before number, how you measured, change, after number.
  • Design-change story: old design, the problem it caused, new design, trade-off.
  • Also useful: a time you were wrong, and a disagreement with a teammate.

Revise: The N+1 problem (opens in a new tab) and == and references (opens in a new tab).

Predict the output

Predict the Integer traps

These two lines are behind many bug stories. Work out what they print.

Round 1 of 2

Two boxed ids with the same value. What is printed?

Integer a = 1000;
Integer b = 1000;
System.out.println(a.equals(b) + " " + (a == b));

Probing questions: "show me where", "what if it is null?"

A probing question is a follow-up that checks you know your own code, such as "show me where" or "what if it is null?".

This example answers "what if the coupon code is null?" twice: the version that throws and the safe version. Then you see the output for each.

Example 5 · Answering "what if the coupon code is null?"

CouponProbeDemo.javaJava
import java.math.BigDecimal;import java.math.RoundingMode;
public class CouponProbeDemo {    static BigDecimal discountBuggy(String code, BigDecimal total) {        if (code.equals("FEST10")) {            return total.multiply(new BigDecimal("0.10")).setScale(2, RoundingMode.HALF_UP);        }        return new BigDecimal("0.00");    }
    static BigDecimal discountSafe(String code, BigDecimal total) {        if ("FEST10".equals(code)) {            return total.multiply(new BigDecimal("0.10")).setScale(2, RoundingMode.HALF_UP);        }        return new BigDecimal("0.00");    }
    public static void main(String[] args) {        BigDecimal total = new BigDecimal("500.00");        String[] codes = {"FEST10", "WRONG", null};        for (String code : codes) {            System.out.println(code + " -> discount " + discountSafe(code, total));        }        try {            discountBuggy(null, total);        } catch (NullPointerException e) {            System.out.println("Buggy version with null: NullPointerException");        }    }}
Output
FEST10 -> discount 50.00
WRONG -> discount 0.00
null -> discount 0.00
Buggy version with null: NullPointerException

What this code does

  • code.equals(...) calls a method on null and throws. "FEST10".equals(code) calls it on a constant that is never null, so a missing code simply means no discount.
  • A good spoken answer: "Today it would throw a NullPointerException and the user would get a 500. I would compare constant-first, and validate the request so a blank code is rejected with 400."
  • Admitting the bug and giving the fix shows ownership; pretending the code is perfect does not.

Answer in three steps: find the place ("OrderService.place"), say what the code does today, then say what happens in the edge case and how you would handle it.

  • "Show me where X happens": class, method, then narrate the flow.
  • "What if it is null, empty or negative?": trace it, then give the fix.
  • "What if two requests come together?": name the race and the lock or constraint.
  • "Why this line?": explain it, or reason out loud honestly.

If you find a bug while answering, say so calmly and give the fix: that is a good sign, not a failure.

Find the bug

Answer the probing questions

For each "what if" question, click the line that breaks.

What if the customer's city is null? Which line throws?

Round 1 of 3

Red flags interviewers notice in copied projects

A red flag is a sign that the candidate did not build what they claim. Interviewers who see many student projects notice the same ones again and again.

Interviewers can read your repository's history in seconds. These three commands show what they may look at.

Terminal
# What an interviewer may look at in your repositorygit log --oneline | head -5git log --format="%ad %s" --date=short | tail -3git shortlog -s -n
  • One huge "initial commit" with the whole project, or every commit on the same day.
  • A README with someone else's name, screenshots or links, or setup steps that do not work.
  • Files the candidate cannot explain: a config class, a dependency, a strange folder.
  • No idea how to run it locally, or secrets such as passwords committed in application.properties.
The fix is honesty plus ownership: say what came from a course or tutorial, and learn every file you keep. Delete what you cannot explain.

Next step

Check your understanding

12 quick questions