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 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.
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.
Problem patterns it solves
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)
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)
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))
Where it is used in real software
Engineers clarify requirements with product managers before building; ambiguous tickets are the top cause of rework.
Reviewers ask about input limits, error cases, and pagination before approving an API, the same questions as in interviews.
Before fixing a production bug, engineers confirm the exact symptoms and scope to avoid fixing the wrong thing.
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.
A clarification checklist
- 1Restate the problem
'So, given an array of integers, I return the indexes of two numbers that sum to the target?'
- 2Ask about input size and ranges
How large can n be? Can values be negative, zero, or very large? Duplicates?
- 3Ask about input properties
Is it sorted? Can I modify it? Is it guaranteed non-empty? Is there always a valid answer?
- 4Ask about output
Return indexes or values? Any order? What if no answer exists: -1, empty array, exception?
- 5Walk through an example
Use the given example or make a small one, including one edge case, and confirm the expected output.
Clarifying 'find the longest substring without repeating characters'
Questions a strong candidate asks, and how answers change the approach
| Question | Possible answer | Impact |
|---|---|---|
| What characters can appear? | Only lowercase English | Use int[26] instead of a hash map |
| Maximum length of s? | 5 x 10^4 | O(n^2) is borderline; aim for O(n) sliding window |
| Can s be empty? | Yes | Return 0 without special errors |
| Return length or the substring? | Length | No 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.
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);Complexity and performance
Out of a 45-minute interview.
Focused on what changes the solution.
Include one edge case.
Trade-offs
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.
If the interviewer says 'you decide', state your assumption out loud and move on.
Variants and related techniques
The same step becomes requirements gathering: functional requirements, scale, and non-goals.
Write your assumptions in the README when you cannot ask.
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.
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.
Practice problems
| Problem | Difficulty | What it trains |
|---|---|---|
| Pick 5 problems and write the contract first | Easy | Inputs, outputs, constraints before code. |
| 1. Two Sum | Easy | Duplicates, one solution, index output. |
| 3. Longest Substring Without Repeating Characters | Medium | Alphabet and empty input. |
| 56. Merge Intervals | Medium | Are intervals sorted? Touching intervals? |