リリース・改善中
コーディング面接対策 ガイド · 1/6
この章は現在、英語でのみ提供しています。
A coding interview asks you to solve an algorithmic problem within a time limit while explaining your reasoning out loud. In Korea the process is often split into an online coding test followed by a technical interview; elsewhere, live coding with an interviewer in a shared editor or on a whiteboard is the norm. The format varies, but the questions underneath are the same: can you understand an unfamiliar problem, pick a suitable data structure and pattern, turn it into readable code, and check your own work?
This chapter covers what interviewers actually evaluate, how to recognize the common problem patterns from clues in the statement, and the vocabulary used in the rest of this guide.
Few interviews grade only the final answer. Most companies use a scorecard with several separate criteria. A candidate who never reaches the optimal solution can still pass on a strong process, and a candidate who types a correct answer in silence can still score poorly.
| Criterion | What is assessed | Good signals |
|---|---|---|
| Understanding | Do you pin down requirements and constraints? | Asks about input size, empty input, duplicates and negatives up front |
| Problem solving | Do you move from brute force to something better? | States the slow approach first, names the bottleneck, improves it |
| Code quality | Is the code correct and readable? | Meaningful names, small functions, careful boundaries |
| Verification | Do you find your own bugs? | Traces a small example by hand and tries extreme inputs |
| Communication | Do you share your thinking? | Says what is being tried when stuck and acts on hints |
The takeaway is that thinking aloud matters as much as raw skill. The interviewer cannot see inside your head, so a decision you never voiced earns no credit.
There are countless interview problems, but far fewer patterns behind their solutions. The core of preparation is learning to spot the clues in a problem statement that point to a pattern.
| Pattern | Clues in the statement | Typical complexity |
|---|---|---|
| Hash map / hash set | "Have we seen this before?", counting, finding a partner | O(n) time, O(n) space |
| Two pointers | Sorted array, closing in from both ends, in-place cleanup |
O(n), or O(n log n) with sorting |
| Sliding window | "Contiguous subarray", longest or shortest stretch | O(n) |
| Prefix sums | Many range-sum queries, number of subarrays summing to k | O(n) setup, O(1) per query |
| Binary search | Sorted data, "smallest value that satisfies a condition" | O(log n) or O(n log n) |
| BFS / DFS | Grids, connectivity, minimum number of moves | O(V + E) |
| Heap | Top k items, a minimum or maximum that keeps changing | O(n log k) |
| Dynamic programming | Counting ways, optimal values, overlapping subproblems | states times transition cost |
| Backtracking | Enumerating all combinations or permutations, small n | exponential |
Here are the three basic patterns in a few lines each. Notice that every one of them walks the input only once.
Two pointers on a sorted array, checking whether two numbers add up to the target. If the sum is too small, move the left pointer; if it is too large, move the right one.
def has_pair_with_sum(sorted_nums: list[int], target: int) -> bool:
lo, hi = 0, len(sorted_nums) - 1
while lo < hi:
total = sorted_nums[lo] + sorted_nums[hi]
if total == target:
return True
if total < target:
lo += 1
else:
hi -= 1
return False
print(has_pair_with_sum([1, 3, 4, 6, 9], 10)) # True (1 + 9)
print(has_pair_with_sum([1, 3, 4, 6, 9], 2)) # FalseA fixed-size sliding window that finds the largest sum of k consecutive elements. Each time the window slides by one, add the value coming in and subtract the value going out.
def max_window_sum(nums: list[int], k: int) -> int:
window = sum(nums[:k])
best = window
for right in range(k, len(nums)):
window += nums[right] - nums[right - k]
best = max(best, window)
return best
print(max_window_sum([2, 1, 5, 1, 3, 2], 3)) # 9 (5 + 1 + 3)A hash set that finds the first value to appear twice. Membership tests are O(n) on a list but O(1) on average for a set.
def first_repeat(items: list[str]) -> str | None:
seen: set[str] = set()
for item in items:
if item in seen:
return item
seen.add(item)
return None
print(first_repeat(["a", "b", "c", "b", "a"])) # bCoding interviews grade understanding, problem solving, code quality, verification and communication alongside correctness. Practice spotting the clues that point to hash maps, two pointers and sliding windows, and build the habit of thinking out loud: with the same skills, you will come across far better. The next chapter walks through solving one problem from start to finish.
コメント 0件
ログイン · ログインするとコメントできます。
最初のコメントを書いてみましょう。