本文へスキップ
製品デスクトップツール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
ディスカッション

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

Pattern Drills

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

The problems in this chapter were written for this guide to drill the patterns. For each one, first run through the procedure from the earlier chapter on your own (clarify, examples, brute force, optimize) and only then read the solution. Afterwards, cover the code and write it again from scratch; that is where most of the learning happens.

Problem 1: Count ranges that sum to exactly k (prefix sums + hash map)

Daily income and spending are given as an integer array amounts (it may contain negatives). Count the contiguous ranges of days whose total is exactly k.

Example: with amounts = [1, 2, -1, 2, 1] and k = 3, the ranges are [1, 2], [2, -1, 2] and [2, 1], so the answer is 3.

Approach: Negative values break the sliding window. Let p be the running prefix sum. A range sums to k exactly when p[j] - p[i] = k, so the number of ranges ending here equals how many earlier prefix sums equal the current prefix minus k. Count prefix sums in a hash map. The key detail is seeding the map with 0 once, which represents the empty prefix.

from collections import defaultdict


def count_sum_k(amounts: list[int], k: int) -> int:
    seen = defaultdict(int)
    seen[0] = 1           # the state before adding anything
    prefix = count = 0
    for x in amounts:
        prefix += x
        count += seen[prefix - k]
        seen[prefix] += 1
    return count


print(count_sum_k([1, 2, -1, 2, 1], 3))  # 3
print(count_sum_k([0, 0], 0))            # 3

Complexity: O(n) time, O(n) space.

Problem 2: Count pairs with sum at most target (two pointers)

Given an integer array nums sorted in ascending order, count the pairs i < j with nums[i] + nums[j] <= target.

Example: with nums = [1, 2, 3, 4, 6] and target = 6, the pairs are (1, 2), (1, 3), (1, 4), (2, 3) and (2, 4), so the answer is 5.

Approach: Put a pointer at each end. If nums[lo] + nums[hi] <= target, every element from lo + 1 through hi can pair with lo, so count hi - lo pairs at once and advance lo. Otherwise, move hi down.

def count_pairs_at_most(nums: list[int], target: int) -> int:
    lo, hi = 0, len(nums) - 1
    count = 0
    while lo < hi:
        if nums[lo] + nums[hi] <= target:
            count += hi - lo
            lo += 1
        else:
            hi -= 1
    return count


print(count_pairs_at_most([1, 2, 3, 4, 6], 6))  # 5
print(count_pairs_at_most([5, 5, 5], 9))        # 0
この章について質問がありますか?
前の章Explaining Complexity and Trade-offs次の章Preparation and the Test Environment

Complexity: O(n) time (O(n log n) if you have to sort first), O(1) space.

Problem 3: Longest range with at most k distinct values (sliding window + hash map)

An access log is given as an array of user IDs, log. Find the length of the longest contiguous range that contains at most k distinct IDs.

Example: with log = ["a", "b", "a", "c", "c", "c"] and k = 2, the answer is 4, from ["a", "c", "c", "c"].

Approach: Keep a count per ID for the current window in a hash map. After adding one ID on the right, if there are more than k distinct IDs, remove from the left until there are not, deleting any ID whose count drops to 0. The size of the map is then the number of distinct IDs.

from collections import Counter


def longest_at_most_k_distinct(log: list[str], k: int) -> int:
    counts: Counter[str] = Counter()
    left = best = 0
    for right, user in enumerate(log):
        counts[user] += 1
        while len(counts) > k:
            counts[log[left]] -= 1
            if counts[log[left]] == 0:
                del counts[log[left]]
            left += 1
        best = max(best, right - left + 1)
    return best


print(longest_at_most_k_distinct(["a", "b", "a", "c", "c", "c"], 2))  # 4
print(longest_at_most_k_distinct(["x", "y"], 0))                      # 0

Complexity: O(n) time, O(k) space.

Problem 4: First ID that occurs exactly once (counting with a hash map)

Given an array of event IDs, return the earliest ID that appears exactly once in the whole array, or None if there is none.

Example: for ["k", "m", "k", "p", "m"] the answer is "p".

Approach: Count occurrences in a first pass, then scan again in the original order for the first value with count 1. Two passes are still O(n).

from collections import Counter


def first_unique(events: list[str]) -> str | None:
    counts = Counter(events)
    for event in events:
        if counts[event] == 1:
            return event
    return None


print(first_unique(["k", "m", "k", "p", "m"]))  # p
print(first_unique(["k", "k"]))                 # None

Problem 5: How many times a value occurs in a sorted array (binary search)

Given a sorted array nums, count the occurrences of x in O(log n) time.

Approach: The count is the difference between the first position holding a value at least x and the first position holding a value greater than x. The standard bisect module gives both directly. If the interviewer asks you to implement it yourself, write a lower_bound like the one below.

from bisect import bisect_left, bisect_right


def lower_bound(nums: list[int], x: int) -> int:
    lo, hi = 0, len(nums)            # the answer lies in [lo, hi]
    while lo < hi:
        mid = (lo + hi) // 2
        if nums[mid] < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


nums = [1, 2, 2, 2, 5, 7]
print(bisect_right(nums, 2) - bisect_left(nums, 2))  # 3
print(lower_bound(nums, 2), lower_bound(nums, 6))    # 1 5

Summary

The five problems drill prefix sums, two pointers, variable-size sliding windows, counting and binary search. Rather than memorizing solutions, check that you can say why you picked a pattern: "negatives rule out a window", "the data is sorted, so close in from both ends". Re-solving the same problems in another language is also a good way to review.

コメント 0件

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

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