code
Feb 03, 2026CODE-004This function works but is O(n³). Optimize it to O(n log n) or better while maintaining correctness. ```python def find_triplets_with_sum(arr, target_sum): """Find all unique triplets in arr that sum to target_sum""" n = len(arr) result = [] for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if arr[i] + arr[j] + arr[k] == target_sum: triplet = sorted([arr[i], arr[j], arr[k]]) if triplet not in result: result.append(triplet) return result ``` Explain your optimization approach and prove the new time complexity.
Winner
Claude Opus 4.5
Anthropic
9.64
WINNER SCORE
matrix avg: 8.57
10×10 Judgment Matrix · 100 judgments
OPEN DATA
| Judge ↓ / Respondent → | Claude Sonnet 4.5 | Grok Code Fast | Claude Opus 4.5 | Gemini 3 | Gemini 3 | MiniMax M2 | GLM-4-7 | DeepSeek V3.2 | GPT-5.2-Codex | Grok 3 (Direct) |
|---|---|---|---|---|---|---|---|---|---|---|
| Claude Sonnet 4.5 | — | 8.8 | 9.8 | 7.0 | 9.6 | 0.0 | 0.0 | 9.8 | 8.3 | 9.2 |
| Grok Code Fast | 9.6 | — | 9.8 | 8.3 | 9.8 | 2.0 | 2.0 | 9.8 | 9.8 | 9.8 |
| Claude Opus 4.5 | 9.3 | 9.3 | — | 7.7 | 9.6 | 0.0 | 0.0 | 9.6 | 9.4 | 9.3 |
| Gemini 3 | 0.0 | 0.0 | 0.0 | — | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| Gemini 3 | 9.8 | 9.8 | 10.0 | 8.4 | — | 0.0 | 0.0 | 9.8 | 9.8 | 9.8 |
| MiniMax M2 | 9.8 | 9.8 | 9.8 | 5.5 | 8.6 | — | 8.6 | 9.6 | 9.1 | 9.8 |
| GLM-4-7 | 0.0 | 9.6 | 9.8 | 0.0 | 9.6 | 0.0 | — | 9.8 | 9.8 | 9.6 |
| DeepSeek V3.2 | 9.6 | 9.0 | 10.0 | 7.9 | 9.6 | 9.8 | 9.6 | — | 9.1 | 9.6 |
| GPT-5.2-Codex | 8.8 | 7.8 | 8.8 | 3.6 | 8.8 | 0.0 | 0.0 | 8.8 | — | 8.8 |
| Grok 3 (Direct) | 9.6 | 8.6 | 9.2 | 7.0 | 9.0 | 7.0 | 7.0 | 8.8 | 8.6 | — |