DeepSeek Competitive Programming: Reasoning for Algorithms
Leverage DeepSeek's math/STEM strengths for competitive programming. Reasoning mode (effort=max) for complex algorithmic problems, pattern recognition, optimization strategies, and edge case handling.
DeepSeek's math and STEM strengths make it unusually good at competitive programming — the kind of algorithmic problem-solving found on Codeforces, LeetCode, and AtCoder. The combination of thinking mode with effort=max and DeepSeek's native mathematical reasoning produces solutions that catch edge cases, explore multiple algorithmic approaches, and optimize for time/space complexity.
The Competitive Programming Prompt Pattern
Solve this competitive programming problem using thinking mode (effort=max).
PROBLEM: [Problem statement with constraints]
APPROACH (in your reasoning):
1. IDENTIFY the problem category (DP, graph, greedy, etc.)
2. ANALYZE constraints — what time/space complexity is required?
3. EXPLORE at least 2 algorithmic approaches
4. EVALUATE each approach against the constraints
5. IDENTIFY edge cases and verify your approach handles them
6. IMPLEMENT the best approach
OUTPUT:
- Time complexity: O(...)
- Space complexity: O(...)
- Explanation of approach (2-3 sentences)
- Complete implementation
Reasoning Mode for Algorithm Design
When to Use effort=max
Problem characteristics that justify max reasoning:
✓ Multiple valid approaches with non-obvious tradeoffs
✓ Constraints require specific complexity (e.g., O(n log n) on 10^5 input)
✓ Edge cases are subtle and easy to miss
✓ Problem involves mathematical insight (number theory, combinatorics)
✓ Dynamic programming with non-obvious state transitions
Use effort=high for:
- Straightforward implementation problems
- Well-known algorithms (BFS, binary search, sliding window)
- Problems where you're confident in the approach
Self-Verification Pattern
After implementing your solution, verify it against these edge cases:
1. MINIMUM inputs (n=0, n=1, empty arrays, single elements)
2. MAXIMUM inputs (n=10^5, all values at limits)
3. EQUAL values (all elements same)
4. NEGATIVE values (if applicable)
5. MONOTONIC sequences (strictly increasing, strictly decreasing)
6. DUPLICATE values
7. BOUNDARY conditions (overflow, underflow)
For each edge case, trace your algorithm's behavior.
If your solution fails any edge case, revise before presenting.
Problem Category Strategies
Dynamic Programming
For DP problems, in your reasoning:
1. DEFINE the state: dp[i] represents...
2. DERIVE the transition: dp[i] = ... (explain why)
3. SPECIFY the base case: dp[0] = ...
4. DETERMINE iteration order: i from 0 to n, or reverse?
5. OPTIMIZE: Can you reduce state dimensions? Use prefix sums?
Example reasoning:
"dp[i][j] = max points using first i items with capacity j.
Transition: dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight[i]] + value[i]).
Base: dp[0][*] = 0, dp[*][0] = 0.
Iterate i from 1 to n, j from 0 to capacity.
Space optimization: Use 1D array iterating j backwards."
Graph Problems
For graph problems, in your reasoning:
1. MODEL the graph: vertices = ?, edges = ?, directed/undirected?
2. CHOOSE the algorithm: BFS (unweighted shortest), Dijkstra (weighted), DFS (connectivity)
3. HANDLE edge cases: disconnected graphs, self-loops, negative weights
4. COMPLEXITY: O(V + E) or O(E log V)?
Example reasoning:
"This is an unweighted shortest path on a grid → BFS.
Vertices: each cell. Edges: adjacent cells (4-directional).
Start: (0, 0). Target: (n-1, m-1).
BFS from start, track distance. Return distance at target or -1.
Complexity: O(n×m)."
Greedy & Sorting
For greedy problems, in your reasoning:
1. PROVE the greedy choice: Why does the locally optimal choice lead to global optimum?
2. If you can't prove it: Is there a counterexample? Consider DP instead.
3. SORTING KEY: What should we sort by? Why?
Example reasoning:
"Sort intervals by end time (not start time).
Greedy: Always pick the interval that ends earliest.
Proof: If we don't pick the earliest-ending interval, we can replace
our first pick with it without reducing the total count.
Counterexample check: Try intervals [(1,10), (2,3), (4,5)] — greedy works."
Complexity Optimization Prompts
Your current solution has time complexity O(n²) and space complexity O(n).
The constraints are n ≤ 10^5, requiring O(n log n) or better.
OPTIMIZATION TASK:
1. Identify the bottleneck — where is the O(n²) coming from?
2. Can this be reduced with:
- Two pointers (already sorted?)
- Binary search (monotonic property?)
- Prefix sums (range queries?)
- Hash map (lookup bottleneck?)
- Monotonic stack/queue (next greater/smaller?)
3. Propose the optimized approach with new complexity analysis
Note:
Pro Move: For LeetCode-style problems, include the problem's official constraints in your prompt. DeepSeek uses constraints to automatically filter out approaches that won't meet the time/space requirements — saving reasoning tokens on dead-end approaches.
Note:
Over-reasoning risk: For well-known algorithms (two-sum, valid parentheses), effort=max may spend tokens exploring approaches you already know work. Use effort=high as default and only bump to max for problems where you're genuinely uncertain about the approach or where edge cases are tricky.
Related Pages
- DeepSeek for Coding — Agentic coding patterns and Claude Code integration for everyday development.
- Math & STEM Reasoning — Competitive programming's mathematical foundation. Proof patterns and verification strategies.
Related Articles
Anthropic Prompt Engineering: Research-Backed Guide
Learn to write clear, direct prompts for Anthropic's Claude AI. Research-backed techniques for better accuracy, precision, and structured outputs from your AI interactions.
Fashion & Editorial Photography SREF Codes
High-end fashion and editorial photography SREF codes for Midjourney including runway, beauty, and magazine-style imagery.
DeepSeek Reasoning Effort Control: High vs Max
Master DeepSeek's reasoning_effort parameter. When high vs max effort, cost implications, diminishing returns curve, and which task categories benefit most from maximum reasoning.