SwiftRelay

← All sprint notes

DeepSeek V4 Pro for Algorithms: A Step-by-Step Guide

Model splitsEN

For algorithm-heavy work, make DeepSeek V4 Pro produce something you can inspect: a precise specification, a justified algorithm, an implementation, and executable tests. Follow this walkthrough using weighted interval scheduling as a running example. The objective is to select compatible jobs with the greatest total reward.

1. Configure Your DeepSeek V4 Pro Connection

Start with a minimal request before attaching a repository or launching an automated coding session. DeepSeek’s documentation lists deepseek-v4-pro as an API model identifier, but confirm the identifier exposed by your chosen provider rather than assuming every relay uses identical routing. ([api-docs.deepseek.com](https://api-docs.deepseek.com/api/responses))

For this walkthrough, use SwiftRelay as the pay-as-you-go connection. With an OpenAI-compatible SDK, set the base URL to https://api.fastapirelay.com/v1. For Claude Code or Gemini CLI, use the bare host, https://api.fastapirelay.com. Keep your API key in an environment variable, outside prompts and committed files. Sign up for SwiftRelay to try the workflow with the small gift credit provided to new accounts.

2. Turn the Scheduling Problem Into a Contract

Do not begin with “solve weighted interval scheduling.” Specify the input and output, then remove ambiguity around compatibility and empty selections. Use the following as your task contract:

  • Each job contains an integer start, finish, reward, and unique identifier.
  • Start must be strictly earlier than finish; rewards may be negative.
  • A job ending when another starts is compatible with that job.
  • Return the maximum reward and selected original identifiers; an empty selection is allowed.
  • Any optimal selection is acceptable when several selections tie.

Add your actual maximum input size and implementation language. Ask DeepSeek V4 Pro to restate the contract and flag unresolved assumptions before writing code.

3. Request Candidate Algorithms Before Implementation

Ask for a short comparison of exhaustive subset search, a proposed greedy rule, and dynamic programming. Require a counterexample for any rejected greedy approach rather than accepting an unsupported dismissal.

Use this prompt: “Compare candidate approaches against this contract. Recommend one, explain its state and transitions, and derive its time and auxiliary-space complexity. Do not implement it yet.” Review whether the recommendation accounts for sorting, predecessor lookup, and reconstruction. Treat the complexity claim as something to verify against the eventual implementation.

4. Check the Recurrence and Reconstruction Rules

Request a finish-time ordering and a precise definition of the predecessor index: the last earlier job whose finish does not exceed the current start. Then ask the model to express the choice between skipping the current job and taking it after a compatible prefix.

Require a compact correctness argument covering those two cases. Also request a hand-worked trace with overlapping jobs, equal finish times, and a negative reward. Before approving code, check that the initial state permits an empty selection and that reconstruction preserves original identifiers.

5. Generate a Small, Testable Implementation

Now request one pure solver function and a separate test module. Keep file parsing, command-line handling, and application integration outside the first patch. Ask for comments explaining the predecessor search boundary and reconstruction decisions, not comments that merely restate each line.

Inspect the generated code for accidental input mutation, inconsistent indexing, and numeric types that cannot represent the largest possible total reward. Run it locally; generated code is a proposal until your test harness accepts it.

6. Differential-Test DeepSeek V4 Pro’s Solution

Ask for an independent exhaustive solver limited to small inputs. Compare its optimal reward with the optimized solver across reproducible randomized cases. Separately validate the returned identifiers, compatibility, and reward sum; do not require identical selections when ties exist.

Include empty input, one job, all-negative rewards, touching intervals, nested intervals, and duplicate time ranges with distinct identifiers. When a case fails, preserve the random seed, minimize the input, and send back the failing example with expected and actual results.

7. Package the Verified Algorithm for Review

Request a focused final patch containing the solver, regression tests, and a brief complexity explanation tied to the code. Re-run the complete test suite after integration, especially if surrounding code transforms timestamps or identifiers.

Keep subsequent DeepSeek V4 Pro requests narrow: one failure, one proposed correction, one verification cycle. With SwiftRelay’s per-token billing, review token usage alongside accepted fixes rather than judging the workflow by how much code it generates. Your deliverable is a tested algorithm with an auditable explanation—not simply a convincing answer.

Keep reading

Back for another lap?Log in