Extrait public
Verrouillé
Restate the problem formally, work small examples by hand, write the brute force and its cost, look for structure (sorting, two pointers, heap, DP, graph, union-find, sweep line), prove why the chosen approach is correct, derive Big-O, then check it fits n = 10^6 in your time budget…
À propos de ce prompt
For a performance-critical function or a hard algorithmic problem: formal restatement, brute-force baseline, candidate techniques compared, a correctness argument, time and space complexity derived step by step, an operations-count estimate against your real input sizes, and an implementation checked against brute force on random inputs. DeepSeek is chosen for its explicit step-by-step reasoning.
Exemple de résultat
STEP 1 — Input: n intervals [s, e) with s < e. Output: max number of intervals overlapping at any instant. Edge: a meeting ending at 10 and one starting at 10 do NOT overlap (half-open).
STEP 3 — Baseline: for each interval, count others overlapping its start → O(n²) = 10^12 comparisons at n = 10^6. Far over budget.
STEP 4
| Idea | Time | Space | Fits? |
| Sweep line on sorted events | O(n log n) | O(n) | yes |
| Min-heap of end times | O(n log n) | O(n) | yes, more code |
| Counting array over time values | O(n + T) | O(T), T = 10^9 | no |
STEP 5 — Invariant: after processing all events at time ≤ t, `active` equals the number of meetings covering t. Ends sorted before starts at equal times → half-open semantics preserved; reversing that order would count 10:00 back-to-back meetings as overlapping.
STEP 6 — Sorting 2n = 2·10^6 events: ≈ 2·10^6 × 21 ≈ 4.2·10^7 comparisons. Python ≈ 10^7 simple ops/s with the C-level sort doing most of the work → expect ≈ 0.5–1 s: over the 200 ms budget → use arrays + numpy argsort, or implement in Go…
Fiche technique
- Modèle
- DeepSeek
- Langue du prompt
- Anglais
- Pour qui
- Developers optimising a core routine, engineers facing a scheduling or matching problem, students of algorithms
- Longueur
- ~606 tokens (estimation)
- Format livré
- Texte du prompt, affiché en ligne après achat
- Rayon
- Code & Développement
Avis
Aucun avis pour l'instant. Seuls les acheteurs de ce prompt peuvent en laisser un.