INTERVIEW MASTERY / ALGORITHM BRIEF

Problem clarification

Problem clarification is the first 3 to 5 minutes of a coding interview: restating the problem, confirming inputs and outputs, and asking about constraints before designing anything.

BeginnerPhase 09 / Topic 1 of 6Mental modelComplexityEdge cases
01

Overview

Problem clarification is the first 3 to 5 minutes of a coding interview: restating the problem, confirming inputs and outputs, and asking about constraints before designing anything. Interviewers deliberately leave details ambiguous to see whether you ask.

The questions you ask decide the algorithm. 'Is the array sorted?' can mean binary search instead of a hash map. 'How large is n?' tells you whether O(n^2) passes. 'Can values be negative?' rules out a sliding window. Clarifying well prevents solving the wrong problem, which is the most expensive mistake in an interview.

A builder confirming the blueprint

A contractor who starts pouring concrete before confirming where the doors go will rebuild the wall later. Five minutes of questions about the blueprint saves days of rework.

02

When to use it

  • At the start of every coding interview problem.
  • Whenever the input format, output format, or edge behavior is not explicitly stated.
  • Before committing to an approach that depends on a property (sorted, distinct, non-negative).
  • When the interviewer adds a follow-up that changes constraints.
03

Problem patterns it solves

Input properties change the algorithm

Recognize it when: sorted, distinct, bounded range, non-negative, fits in memory.

  • 1. Two Sum vs 167. Two Sum II (sorted)
  • 209. Minimum Size Subarray Sum (positives) vs 560. Subarray Sum Equals K (negatives)
Output format

Recognize it when: indexes or values, any order or sorted, all answers or one.

  • 15. 3Sum (unique triplets)
  • 46. Permutations (any order)
  • 1. Two Sum (exactly one solution)
Constraints reveal the target complexity

Recognize it when: n <= 20 suggests exponential; n <= 10^5 suggests O(n log n).

  • 78. Subsets (n <= 10)
  • 300. Longest Increasing Subsequence (n <= 2500 vs follow-up O(n log n))
04

Where it is used in real software

Requirements gathering

Engineers clarify requirements with product managers before building; ambiguous tickets are the top cause of rework.

API design reviews

Reviewers ask about input limits, error cases, and pagination before approving an API, the same questions as in interviews.

Incident response

Before fixing a production bug, engineers confirm the exact symptoms and scope to avoid fixing the wrong thing.

05

Key terms

Restate
Repeat the problem in your own words to confirm understanding.
Input contract
Types, ranges, sizes, and guarantees about the input.
Output contract
What to return, format, and behavior when there is no answer.
Worked example
A small example you and the interviewer agree on before coding.
06

A clarification checklist

  1. 1
    Restate the problem

    'So, given an array of integers, I return the indexes of two numbers that sum to the target?'

  2. 2
    Ask about input size and ranges

    How large can n be? Can values be negative, zero, or very large? Duplicates?

  3. 3
    Ask about input properties

    Is it sorted? Can I modify it? Is it guaranteed non-empty? Is there always a valid answer?

  4. 4
    Ask about output

    Return indexes or values? Any order? What if no answer exists: -1, empty array, exception?

  5. 5
    Walk through an example

    Use the given example or make a small one, including one edge case, and confirm the expected output.

07

Clarifying 'find the longest substring without repeating characters'

Questions a strong candidate asks, and how answers change the approach

Step 1 / 5
QuestionPossible answerImpact
What characters can appear?Only lowercase EnglishUse int[26] instead of a hash map
Maximum length of s?5 x 10^4O(n^2) is borderline; aim for O(n) sliding window
Can s be empty?YesReturn 0 without special errors
Return length or the substring?LengthNo need to track start index
Case sensitive?Yes'a' and 'A' are different characters

NOWQuestion: What characters can appear? | Possible answer: Only lowercase English | Impact: Use int[26] instead of a hash map

Five quick questions fixed the data structure, the target complexity, the edge case, and the output. Now you can design without guessing.

08

Implementation

/** * Write the agreed contract at the top of your solution. * * Input:  s, a string of ASCII characters, 0 <= s.length <= 5 * 10^4 * Output: length of the longest substring with all distinct characters * Edge:   empty string -> 0 * Target: O(n) time, O(1) space (bounded alphabet) */function lengthOfLongestSubstring(s) {  const lastSeen = new Map();  let left = 0, best = 0;  for (let right = 0; right < s.length; right++) {    const prev = lastSeen.get(s[right]);    if (prev !== undefined && prev >= left) left = prev + 1;    lastSeen.set(s[right], right);    best = Math.max(best, right - left + 1);  }  return best;} // Verify the agreed examples before moving onconsole.assert(lengthOfLongestSubstring("abcabcbb") === 3);console.assert(lengthOfLongestSubstring("") === 0);console.assert(lengthOfLongestSubstring("bbbb") === 1);
09

Complexity and performance

Time to spend3-5 minutes

Out of a 45-minute interview.

Questions3-6

Focused on what changes the solution.

Examples1-2

Include one edge case.

10

Trade-offs

Too few vs too many questions

Skipping clarification risks solving the wrong problem; asking about every trivial detail wastes time. Ask the questions whose answers would change your algorithm or output.

Assume vs ask

If the interviewer says 'you decide', state your assumption out loud and move on.

11

Variants and related techniques

System and design interviews

The same step becomes requirements gathering: functional requirements, scale, and non-goals.

Take-home assignments

Write your assumptions in the README when you cannot ask.

12

Common mistakes

  • Starting to code immediately.

    Fix: Pause, restate, and ask at least about size, properties, and output.

  • Not confirming the output format.

    Fix: Returning values when indexes were expected fails every test.

  • Ignoring the given constraints section.

    Fix: Constraints often tell you the intended complexity directly.

13

Interview questions

What should you ask before solving any array problem?

Size of n, value range (negatives, overflow), duplicates, whether it is sorted, whether you may modify it, what to return, and what to do when there is no answer.

What if the interviewer refuses to clarify?

State a reasonable assumption explicitly, design for it, and mention how the solution would change if the assumption were different.

14

Practice problems

ProblemDifficultyWhat it trains
Pick 5 problems and write the contract firstEasyInputs, outputs, constraints before code.
1. Two SumEasyDuplicates, one solution, index output.
3. Longest Substring Without Repeating CharactersMediumAlphabet and empty input.
56. Merge IntervalsMediumAre intervals sorted? Touching intervals?