Skip to content

Coding interviews

Take Charge of a Coding Interview by Asking What the Interviewer Wants

A simple problem can sink a strong candidate who guesses the wrong target. This guide uses one deceptively easy question to show how coding interviews differ, how to find out what is being judged and what a data-driven answer looks like.

Your first hour with George Li (60 minutes by video, $250) ends with a written plan within one working day.

Book your first hour ($250)

A simple question that goes wrong

Picture a student interviewing for an entry-level software job. The interviewer shows a small table of quantity bands for a product. The more a customer buys, the lower the price per unit: one band for the smallest orders, then three more bands for larger quantities, with the last band open ended. The task is to write a function that takes a quantity and returns the right unit price.

The student thinks it looks easier than the classic warm-up exercises and writes a chain of conditions, one per band, with a fallback for values that match nothing. It works. Yet the interviewer simply moves on, and the next day a rejection arrives.

The story comes from a real screening in which the interviewer was unhappy that so many candidates wrote the straightforward version. He wanted a structure that kept the price bands in a table and looked them up, and a candidate who missed that was filtered out.

Whether or not you agree with that judgment, the lesson is practical: the answer that is correct is not always the answer that is expected, and you can find out which one is wanted by asking.

Summary of the lesson

  • Interview styles reward different answers, so work out which style you are in.
  • Control the conversation. Ask clarifying questions until the target is clear instead of guessing what is in the interviewer's mind.
  • A table-driven approach is built for change, which is probably what this interviewer cared about.

Two kinds of coding interview

Coding rounds usually fall into two groups.

  • Algorithms and data structures. You are judged on picking the right data structure and reaching an efficient solution with sensible time and memory costs.
  • Practical building. You are judged on hands-on engineering: structuring a feature, writing readable code and handling the many parts of a working program.

The prompt often tells you which is which. Inverting a binary tree is an algorithm question. Designing an autocomplete search box is a building question, though the two can blend, for example when you use a trie while designing that box.

What the algorithm round rewards

Speed and correctness with the right tools. Variable names, extensibility and community style matter little, or at least come second. Short names and changing the input in place are fine as long as the solution passes the tests within the limits. Interviewers in this mode usually want to see that you can work through a recursive idea or a linked structure quickly and cleanly.

What the practical round rewards

More experienced candidates meet the practical style more often. Readable code, a structure that can grow, error handling and awareness of the whole life of a program are all fair game, because that is how real software succeeds.

Neither style is better. They simply test different things, and you need to know which one is in front of you.

How to take control

Your working memory is limited, so avoid spending it on side issues before the main goal is done. If you are polishing names when the interviewer only cares about complexity, or hurrying through a messy hack when they want clean design, you waste effort.

Two habits help.

  1. Narrate your thinking. Say what you are assuming and why, so the interviewer can confirm your direction or correct it early.
  2. Ask the framing question. "Should I write production-quality code, or are you more interested in how I handle the algorithm and data structure?" may be the highest-value sentence you can say. The reply tells you whether to optimize for maintainability or for efficiency.

Keep asking until you understand the target. Clarifying is a sign of seniority, not weakness.

Was the question fair?

Many engineers would call it a weak question for new graduates. It does not separate strong programmers from average ones. It checks whether a candidate happens to know one organizing pattern, which a bright student can learn in an afternoon and an average developer who has read a good book can reproduce. Using that as the only filter for new graduates does not find the people who reason best.

A better screen asks for abstract thinking. Many interviewers favor questions on recursion and on manipulating linked structures, not because everyone uses them daily, but because they reveal how well a person handles abstraction. That is the sort of mental skill that tends to mark strong programmers.

The moral for you: do not be afraid to ask, and never assume the interviewer's priorities if they have not said them.

The table-driven answer, explained

If you are curious about the technical side, here is what the interviewer wanted.

The idea behind a table-driven solution
Quantity bandUnit price level
Smallest ordersHighest
Next band upLower
Larger bandLower again
Open-ended top bandLowest

The core idea is to separate data from logic. In the first version, every price lives inside the function as a literal value, mixed with the rules for choosing among them. In the table-driven version, the prices and ranges sit in a data structure, and the function only searches it.

Why does that help? Pricing is a business policy, and policies like that get revised often. If the table is outside the logic, an update means editing a row instead of rewriting conditions, and the change cannot damage the code around it. You have isolated the unstable part.

The attempt shown in the original discussion was only partway there. The table was still inside the function, and numbers still appeared as bare constants. A fuller version stores each band with a lower bound, an upper bound and a price in a separate configuration file, imports it, and searches for the band that contains the quantity. It also handles quantities that fall outside every band.

A faster lookup

If the bands are sorted, you can search them with binary search instead of scanning from the top. Compare the quantity with the upper bound of the middle band and discard half the list at each step. With only a few bands the speed gain is trivial, but the technique shows that you understand how searching scales.

What about performance?

It may feel as if a handful of conditions must run faster than a loop. In terms of Big O, both are constant time here, because the number of comparisons does not grow with the input. Real timing is murky: modern engines optimize loops heavily, and trustworthy micro-benchmarks are hard to build because results shift with the engine and the loop body. Do not choose between the two on speed alone.

Clarifying questions worth asking

These work in almost any coding round, and they take only a minute.

  • What are the inputs, and how large can they get? Size changes which approach is sensible.
  • What should happen with bad or missing input? The answer decides how much error handling to write.
  • Is this code for a one-time script, a production system or a speed contest? That is the framing question again, asked in another form.
  • May I assume the data is sorted, unique or already validated? Each assumption can simplify the solution.
  • Do you want me to optimize for time, for memory or for readability? Interviewers often have a preference.
  • How should I handle changes later? If the rules might change, a data-driven design is a better bet.

If the interviewer shrugs and says "your call," that is useful too. Pick the approach, say why, and mention what you would change if the priority were different. You will have shown judgment either way.

Practice drill

Take three simple problems and answer each one twice, once as an algorithm round and once as a practical one. For the algorithm version, aim for the cleanest efficient approach. For the practical version, focus on naming, structure and how the code handles change. Comparing the two teaches you what each style looks like on the page, and it makes the framing question feel natural.

What to do in your next interview

  • Read the prompt and decide whether it looks like an algorithm or a practical problem.
  • State your assumptions aloud.
  • Ask the framing question before you write code.
  • Write the simple version first if time is short, then say how you would make it more flexible.
  • When you finish, discuss trade-offs, such as readability against speed and flexibility against simplicity.

Questions

Is it okay to ask the interviewer what they are looking for?

Yes. Clarifying questions show good judgment, and they save you from solving the wrong problem. Ask early and keep your questions specific.

When is a simple chain of conditions acceptable?

In an algorithm-focused round, or when requirements are small and stable, a direct solution is fine. In a practical round, a data-driven structure is usually safer.

What does table-driven mean?

It means keeping rules and values in a data structure that the code reads, instead of hard-coding them into the logic, so that updating the rules does not require changing the logic.

Does a loop run slower than separate conditions?

Not in any way that matters here. Both do a fixed number of comparisons, and real speed depends on the engine, so choose the version that is clearer and easier to change.

Want help with your own applications? See a career coach for college internships, internship interview coaching, or resume review for internships.

Start with one hour

  • Your first purchase is refundable for unused time within 7 days. Nothing renews. Refund terms