本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペースはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらく

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシープライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
012345678901234567890123456789012345678901234567890123456789
昨日
012345678901234567890123456789012345678901234567890123456789
累計閲覧
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

コーディング面接対策 ドキュメント
コーディング面接対策
Coding Interview ConceptsA Problem-Solving ProcedureImplementing the PatternsExplaining Complexity and Trade-offsPattern DrillsPreparation and the Test Environment
ディスカッション

コーディング面接対策 ガイド · 4/6

Explaining Complexity and Trade-offs

この章は現在、英語でのみ提供しています。

In an interview, getting the complexity right is not enough: you have to explain it. "It's O(n)" convinces far less than "n is this, and this operation happens this many times." This chapter covers how to explain complexity out loud, how to infer the target complexity from the input size, and how to discuss trade-offs between solutions.

Saying it out loud, in order

When you state a complexity, cover three things in turn.

  1. Define the variables: say what you are counting, for example "n is the array length and m is the number of queries."
  2. Name the dominant work: point at what happens most often, for example "the outer loop runs n times and each hash map lookup is O(1) on average."
  3. State the space: give the extra memory beyond the input. For recursion, include the depth of the call stack.

For the longest-window-without-repeats solution from the previous chapter, it sounds like this: "n is the length of the string. right moves n times, and left only moves forward, so it moves at most n times as well. Each dictionary lookup and update is O(1) on average, so the time is O(n). The dictionary only holds distinct characters, so the space is O(min(n, σ))."

Inferring the target complexity from the input size

Constraints are a hint about the complexity the problem setter expects. A rough rule of thumb is that a compiled language handles on the order of 10⁸ simple operations per second, and Python handles tens of times fewer. Exact figures depend on the machine, so use only the order of magnitude.

Size of nComplexity that usually passesApproaches to consider
around 10O(n!)permutation backtracking
around 20O(2ⁿ)subsets, bitmasks
around 500O(n³)triple loops, interval DP
around 5,000O(n²)double loops, 2D DP
10⁵ to 10⁶O(n log n), O(n)sorting, heaps, two pointers, hash maps
largerO(log n), O(1)binary search, a formula

One problem, three solutions

Here are three ways to answer "does the array contain two numbers that sum to the target?", followed by a comparison.

def has_pair_brute(nums: list[int], target: int) -> bool:
    # O(n^2) time, O(1) extra space
    for i in range(len(nums)):
        for j in range(i + 1, len(nums)):
            if nums[i] + nums[j] == target:
                return True
    return False


def has_pair_sorted(nums: list[int], target: int) -> bool:
    # O(n log n) time; O(n) for the sorted copy (almost nothing extra if sorted in place)
    arr = sorted(nums)
    lo, hi = 0, len(arr) - 1
    while lo < hi:
        total = arr[lo] + arr[hi]
        if total == target:
            return True
        lo, hi = (lo + 1, hi) if total < target else (lo, hi - 1)
    return False


def has_pair_hash(nums: list[int], target: int) -> bool:
    # O(n) average time, O(n) space
    seen: set[int] = set()
    for x in nums:
        if target - x in seen:
            return True
        seen.add(x)
    return False


for f in (has_pair_brute, has_pair_sorted, has_pair_hash):
    print(f.__name__, f([4, 7, 1, 9], 10), f([4, 7, 1, 9], 2))
この章について質問がありますか?
前の章Implementing the Patterns次の章Pattern Drills
SolutionTimeExtra spaceKeeps original indicesChoose it when
Double loopO(n²)O(1)yesn is tiny, or as a reference answer
Sort + two pointersO(n log n)O(1) to O(n)nomemory is tight or the data is already sorted
Hash setO(n) averageO(n)yes (with a map)you need the best average time

If the interviewer asks "can you get the memory down to O(1)?", explain the trade-off of moving from the hash set to sort plus two pointers. To be precise, also mention that hash tables are O(1) on average but can degrade in the worst case because of collisions.

When nested loops are still O(n)

A sliding window has a while inside a for, which looks like O(n²), but the left pointer that the inner loop advances can increase at most n times over the entire run. Adding up the total work across all iterations like this is called amortized analysis. Counting the moves makes it concrete.

def count_moves(nums: list[int], target: int) -> tuple[int, int]:
    left = total = 0
    right_moves = left_moves = 0
    for value in nums:
        right_moves += 1
        total += value
        while total >= target:
            total -= nums[left]
            left += 1
            left_moves += 1
    return right_moves, left_moves


print(count_moves([1] * 1000, 3))  # (1000, 998): at most 2n moves combined

Hidden costs in Python

Even with a correct analysis, misjudging the cost of a language operation produces slow code. These are the usual suspects.

from collections import deque

items = list(range(10))

# list.pop(0) shifts every remaining element: O(n)
queue = deque(items)
first = queue.popleft()          # deque operations at either end are O(1)

# "in" is O(n) on a list but O(1) on average for a set
lookup = set(items)
print(7 in lookup)

# slicing copies: nums[i:j] costs O(j - i)
window_sum = sum(items[2:5])

# repeated string += can be slow; use join instead
text = "".join(str(x) for x in items)
print(first, window_sum, text)

Summary

Explain complexity by defining the variables, naming the dominant work and stating the extra space. Working backwards from the constraints to a target complexity narrows down the right pattern quickly. Most problems have several solutions that trade time for space, so be ready to explain why you chose one and what the alternatives are.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。