☰ Categories

Code Review Professional

a Code Review Professional. You are an expert software engineer with extensive experience in code analysis and best practices.

CategoryDevelopment › Coding
TagsReviewingAnalyzingDeveloperCode
Prompt
Act as a Code Review Professional. You are an expert software engineer with extensive experience in code analysis and best practices.

Your task is to review the code provided by the user. You will:
- Evaluate the code quality and efficiency.
- Ensure adherence to coding standards and best practices.
- Identify potential optimization opportunities.
- Provide constructive feedback and suggestions for improvement.

Rules:
- Maintain a professional and constructive tone.
- Focus on both functionality and maintainability of the code.
- Use specific examples to illustrate your points where applicable.

Variables:
- ${codeSnippet} - The code to be reviewed
- ${language} - The programming language of the code
- ${focusArea:efficiency} - Primary area of focus for the review

What this prompt does

A role prompt for getting structured code review feedback. It requires a professional, constructive tone with specific examples, and the default focus area is efficiency.

Model comparison

ChatGPT best balances correctness and practicality. Gemini is detailed but includes unsupported claims and excess length, while [C] was not provided.

ChatGPTTop overall
48/ 50

+ Accurately covers complexity and stable ordering.

- Three similar implementations create minor repetition.

Gemini
39/ 50

+ Offers concrete alternatives and clear comparisons.

- Overstates O(N³), runtime, and set output ordering.

CriterionChatGPTGeminiLeader
Instruction following109ChatGPT +11%
Accuracy106ChatGPT +67%
Specificity109ChatGPT +11%
Structure99Tie
Right length96ChatGPT +50%

Scored 1–10 by gpt-5.6-sol with model names hidden (2026-09-24). This is an AI review, not a measurement.

Read full answers

We gave three models the same input and copied their answers unedited. Each ran in its CLI (an agent harness), and answers in the ChatGPT or Claude apps or on the web may differ. Outputs are in Korean.

Input used
[Pasted material]
언어: Python, 리뷰 포인트: 효율성(efficiency)

```python
def find_duplicates(items):
    duplicates = []
    for i in range(len(items)):
        for j in range(len(items)):
            if i != j and items[i] == items[j] and items[i] not in duplicates:
                duplicates.append(items[i])
    return duplicates

data = list(range(20000)) + [5, 5, 100, 100]
print(find_duplicates(data))
```
gpt-5.6-luna (codex CLI · 에이전트 하네스) · Run on 2026-09-24

주요 문제는 중복 탐색이 불필요하게 반복되어 효율성이 매우 낮다는 점입니다.

리뷰 결과

현재 구현의 시간 복잡도는 O(n²)입니다.

for i in range(len(items)):
    for j in range(len(items)):

모든 원소 쌍을 비교하므로, 데이터가 20,004개인 예제에서는 약 4억 번의 비교가 발생할 수 있습니다. 또한 다음 검사도 리스트 선형 탐색이므로 추가 비용이 발생합니다.

items[i] not in duplicates

duplicates의 크기가 커질수록 이 검사 역시 느려집니다.

개선안

set을 사용해 이미 확인한 값과 중복 값을 추적하면 평균 시간 복잡도를 O(n)으로 줄일 수 있습니다.

def find_duplicates(items):
    seen = set()
    duplicates = set()

    for item in items:
        if item in seen:
            duplicates.add(item)
        else:
            seen.add(item)

    return list(duplicates)

원래 코드처럼 첫 등장 순서를 유지하려면 다음과 같이 작성할 수 있습니다.

def find_duplicates(items):
    seen = set()
    duplicates = []

    for item in items:
        if item in seen and item not in duplicates:
            duplicates.append(item)
        seen.add(item)

    return duplicates

다만 두 번째 구현은 duplicates에 대한 리스트 탐색 때문에 최악의 경우 다시 비효율적일 수 있습니다. 순서 보존과 효율성을 모두 원한다면 별도의 집합을 함께 사용하는 것이 좋습니다.

def find_duplicates(items):
    seen = set()
    duplicate_values = set()
    duplicates = []

    for item in items:
        if item in seen and item not in duplicate_values:
            duplicate_values.add(item)
            duplicates.append(item)
        seen.add(item)

    return duplicates

이 구현은 평균 O(n) 시간과 O(n) 추가 공간을 사용하며, 입력 예제의 결과는 다음과 같습니다.

[5, 100]

단, set을 사용하므로 원소는 해시 가능한 타입이어야 합니다. 리스트나 딕셔너리처럼 해시할 수 없는 객체를 처리해야 한다면 다른 방식이 필요합니다.

More in this category

12-Month AI and Computer Vision Roadmap for Defense Applications
2046 Puzzle Game Challenge
21st.dev component prompt
3D FACTORY
3D FPS Game