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
Grok 4.20
openrouter
9.49
WINNER SCORE
matrix avg: 8.87
10×10 Judgment Matrix · 89 judgments
OPEN DATA
| Judge ↓ / Respondent → | GPT-5.4 | Claude Opus 4.6 | Gemini 3.1 Pro | Claude Sonnet 4.6 | Grok 4.20 | DeepSeek V4 | GPT-OSS-120B | Gemini 3 | MiniMax M2.5 | MiMo-V2-Flash |
|---|---|---|---|---|---|---|---|---|---|---|
| GPT-5.4 | — | 9.2 | 3.6 | 8.6 | 9.6 | 8.4 | 6.5 | 8.8 | 5.7 | 7.8 |
| Claude Opus 4.6 | 10.0 | — | 7.1 | 9.8 | 9.8 | 8.8 | 9.2 | 9.2 | 8.7 | 9.2 |
| Gemini 3.1 Pro | 10.0 | 9.2 | — | 9.0 | 10.0 | 8.2 | 8.1 | 10.0 | 7.2 | 10.0 |
| Claude Sonnet 4.6 | 9.4 | 9.2 | 7.3 | — | 9.2 | 8.3 | 9.0 | 8.6 | 9.0 | 9.0 |
| Grok 4.20 | 8.8 | 8.4 | 7.9 | 9.0 | — | 6.8 | 8.8 | 7.8 | 8.7 | 8.6 |
| DeepSeek V4 | 9.4 | 9.4 | 9.1 | 9.6 | 9.6 | — | 9.6 | 9.6 | 9.7 | 9.4 |
| GPT-OSS-120B | 8.8 | 8.8 | 7.8 | · | 8.8 | 7.5 | — | 8.8 | 8.3 | 8.6 |
| Gemini 3 | 10.0 | 9.8 | 9.8 | 10.0 | 10.0 | 9.8 | 9.6 | — | 9.4 | 10.0 |
| MiniMax M2.5 | 9.8 | 8.8 | 8.3 | 10.0 | 9.3 | 8.8 | 8.6 | 8.4 | — | 8.8 |
| MiMo-V2-Flash | 8.8 | 9.0 | 8.6 | 9.4 | 9.2 | 8.8 | 9.6 | 9.3 | 9.0 | — |