Shared Approver Lookup accepts a copied ancestor
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start with the judge spec in web/judges/shared-approver-lookup.json and the identity contract in problem-bank/variants.json, then see how generateHarness in web/compiler-explorer.js serializes returned trees and how checkAnswer in web/lib.js compares them. Check linked PR #846 first, since it may already cover this. Done means a copied ancestor fails with a per-case error, the original node still passes 6/6, and tree-building exercises that allow new nodes are unaffected.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Observed behavior
Shared Approver Lookup (lowest-common-ancestor-of-a-binary-tree) accepts a newly allocated copy of the correct ancestor's subtree. The copied answer passes all six built-in cases in C, C++, Java, Python and JavaScript, even though the scenario requires the existing input node.
Expected behavior
A copied ancestor should fail with a per-case error. Returning the original ancestor should still pass. The contract in problem-bank/variants.json explicitly states: "the original node must be returned, not a copy."
Reproduction
- Use a source checkout at revision
7023a392dfbd26656c73098b90dad43ec3b751b6. - Load the judge specification from
web/judges/shared-approver-lookup.json. - Use
generateHarness("c", spec, candidateCode)fromweb/compiler-explorer.jsto generatesolution.cwith the C candidate solution below. The harness suppliesstruct TreeNode. - Compile with
gcc -std=c17 solution.c -o solutionand run the generated program. - Parse its output with
parseCompilerResultsand grade each result against the judge's cases usingcheckAnswerfromweb/lib.js. Observe that all six cases pass, although the solution returns newly allocated copies. - Replace
return copySubtree(findAncestor(root, p, q));withreturn findAncestor(root, p, q);, regenerate the harness, and rerun. This version also passes 6/6, but returns the required original node.
The incorrect C candidate solution used in step 3:
#include <stdlib.h>
static struct TreeNode* findAncestor(
struct TreeNode* root,
struct TreeNode* p,
struct TreeNode* q
) {
if (!root || root == p || root == q)
return root;
struct TreeNode* left = findAncestor(root->left, p, q);
struct TreeNode* right = findAncestor(root->right, p, q);
return left && right ? root : left ? left : right;
}
static struct TreeNode* copySubtree(struct TreeNode* root) {
if (!root)
return NULL;
struct TreeNode* copy = malloc(sizeof(*copy));
if (!copy)
exit(EXIT_FAILURE);
copy->val = root->val;
copy->left = copySubtree(root->left);
copy->right = copySubtree(root->right);
return copy;
}
struct TreeNode* nearestSharedApprover(
struct TreeNode* root,
struct TreeNode* p,
struct TreeNode* q
) {
return copySubtree(findAncestor(root, p, q));
}
CodeTrial version
codetrial 0.1.0 (7023a39)
Environment
OS: Windows x86_64
Browser: Not used; runner-level reproduction
Language: C, C++, Java, Python and JavaScript
Interview loop: Not applicable
Problem: Shared Approver Lookup (lowest-common-ancestor-of-a-binary-tree)
REACTO or STAR step: Not applicable
Reconnect: Not applicable
Node.js v24.19.0; MinGW GCC/G++ 15.2.0; CPython 3.13.5.
C and C++ were compiled from the generated harnesses. Python used the exported driver, JavaScript used the actual worker source in a Node VM, and Java used the generated harness on Compiler Explorer java2501.
Sanitized evidence
The copied-ancestor solution passed all six built-in cases in all five languages.
| Language | Copied ancestor |
|---|---|
| C | 6/6 passed |
| C++ | 6/6 passed |
| Java | 6/6 passed |
| Python | 6/6 passed |
| JavaScript | 6/6 passed |
Serialization preserves values and shape but loses node identity.
I plan to capture the input node identities before candidate execution and validate the returned node before serialization for binary-tree outputs with treeNodeValue arguments. Tree-building exercises that allow new nodes should remain unaffected.
A JavaScript prototype keeps the original-node solution at 6/6, rejects the copied solution in all six cases, and accepts an allocation-allowed tree control. Please assign this issue to me.
Public data confirmation
- I removed credentials, session tokens, candidate recordings, and personal interview content from this public report.
- Ngôn ngữ chính
- Rust
- Star
- 236
- Fork
- 153
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 187
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của sysprog21/codetrial
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Unify Java harness validation error messagesCó thể đã có người làm @weichieh0204 đã nhận hôm nay. Đang mở
sysprog21/codetrial#872 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Inferred void class operations are never checked against the starter's return typeCó thể đã có người làm @papaya0112 đã nhận hôm nay. Đang mở
sysprog21/codetrial#871 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Edge Thumbnail Store accepts a store that does not refresh a key on overwriteCó thể đã có người làm @BOBOGUAGUA428 đã nhận hôm nay. Đang mở
sysprog21/codetrial#869 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của sysprog21/codetrial
Issue tương tự
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
manaflow-ai/cmux#59692 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Retire stale Python-parity labels in Rust ingress and auth testsCó thể đã có người làm @github-actions đã nhận hôm nay. Đang mởfactory factory:building factory:unowned ralph-status:in-progress via:opencode-free/hy4-flash-free
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
JoshCLWren/comic-pile#5874 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status:ready unit
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
nonagenticai/conveyor#787 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày