Coding interview
Алгоритмическое собеседование
A hiring round where you solve a programming problem, explain your approach, and check that your code works. In an algorithm-focused round, you’ll often discuss how its time and memory needs grow with the input.
Also known as: алгоритмы на собеседовании
What is a coding interview?
A coding interview is a technical hiring round in which you write code to solve a problem. The term is broad: some employers ask you to debug existing code or add a feature, while others focus on data structures and algorithms. In an algorithm-focused round, the task is usually small enough to fit in a function. You might check whether a list contains duplicates or find a route through a graph. Unlike a system design interview, the focus is on getting a specific piece of code to behave correctly, not on designing the larger service around it.
What happens during the round?
In a live session, you typically read a prompt, discuss it with the interviewer, and write code in a shared editor. Some editors let you run tests; others require you to walk through the code by hand. An employer may also use a timed online assessment for similar problems, but without an interviewer to clarify the prompt or give hints.
Start by agreeing on what the program should return. Are empty inputs allowed? If there are several valid answers, can you return any of them? Then sketch a straightforward solution and compare its cost with the input limits. While coding, explain decisions that affect correctness or performance rather than narrating every keystroke. Finish by tracing a representative example and the edge cases most likely to expose a bug.
Example: Find the first repeated value
Suppose you need to return the first integer you encounter that has already appeared, or None if no value repeats. For [4, 8, 8, 4], the answer is 8: its second occurrence comes before the second 4. Clarifying that meaning of “first” matters more than immediately reaching for a familiar technique.
def first_repeat(values):
seen = set()
for value in values:
if value in seen:
return value
seen.add(value)
return None
At each step, the set holds the values from earlier positions. That makes membership enough to identify a repeat, and scanning left to right ensures that the function returns the earliest second occurrence. Checking every earlier position instead would take O(n²) time on a list of n distinct values. With average constant-time set operations, the set-based solution takes O(n) time on average for a full pass and uses up to O(n) extra space. Test it with an empty list, a list with no repeats, and a list with more than one repeated value.
What interviewers look for
Scoring varies, but common criteria include correctness, readable code, a justified complexity estimate, and how you respond to questions or hints. An optimal runtime does not fix a wrong interpretation of the prompt. Conversely, a simple solution may be entirely appropriate for small inputs, and explaining why is part of the exercise.
To prepare, practice one language well enough to use its built-in collections without looking up basic syntax. After solving a practice problem, explain why your chosen data structure helps and name an input that would break a plausible wrong solution. A mock interview can reveal whether you can do both while someone is asking follow-up questions.