How do I check correctness?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn How do I check correctness?
Short explanation:
Correctness means the implementation satisfies the required behavior for valid, invalid and concurrent inputs. A review begins with the intended rule, because readable or compilable code can still implement the wrong rule. Trace the inputs, state changes and outputs before judging style.
Key points:
-
Compare code with the required behavior, including empty and invalid inputs.
-
Trace state changes and check return values.
-
Ask whether concurrent requests can break the rule.
-
Write down an invariant such as “stock cannot become negative” and look for a path that violates it.
Interview point:
- Explain the failing input or interleaving clearly enough that another developer can reproduce the problem.
Adapted from 11_AI_CODE_REVIEW.md · “How do I check correctness?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.