C tests accept a wrong next pointer on the last node in Org Chart Row Navigation
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Observed behavior
In Org Chart Row Navigation (Populating Next Right Pointers in Each Node II), the C tests accept a solution whose last next pointer is wrong.
The solution below links each row correctly, then points the last node of the bottom row back to the first node of that row. That node should point to NULL. In C it passes 5/5. The same code in C++ passes 1/5, and every failing case shows "next pointers do not match the tree level order." Java, JavaScript and Python give the same 1/5 with the same message.
static struct Node* rows[128];
struct Node* linkRowNeighbors(struct Node* root) {
int head = 0, tail = 0;
if (root) rows[tail++] = root;
while (head < tail) {
int end = tail;
for (int i = head; i < end; i++) {
rows[i]->next = i + 1 < end ? rows[i + 1] : NULL;
if (rows[i]->left) rows[tail++] = rows[i]->left;
if (rows[i]->right) rows[tail++] = rows[i]->right;
}
if (tail == end) rows[end - 1]->next = rows[head];
head = end;
}
return root;
}
A wrong next earlier in the tree is not caught cleanly either. If the root's next points to itself, C reports [[1]] for "sparse final level" with no message, so the candidate cannot tell what went wrong.
Expected behavior
C fails a wrong next pointer with "next pointers do not match the tree level order.", like the other four languages. A correct solution still passes 5/5.
Reproduction
- Open Org Chart Row Navigation and select C.
- Paste the solution above and run tests. All 5 cases pass.
- Switch to C++, paste the same logic written with
vector<Node*>, and run tests. 4 cases fail with the message above.
CodeTrial version
codetrial 0.1.0 (4faffce)
Environment
OS: Windows 11
Browser: Chromium 155.0.8059.80
Language: C (C++, Java, JavaScript and Python 3 checked for comparison)
Interview loop: Coding
Problem: Org Chart Row Navigation (LeetCode 117)
REACTO or STAR step: Test
Reconnect: None
Sanitized evidence
C, with the solution above:
5/5 test cases passed
OK sparse final level
OK empty tree
OK single node
OK missing middle children
OK one child
C++, with the same logic:
1/5 test cases passed
FAIL sparse final level
input [[1,2,3,4,5,null,7]]
next pointers do not match the tree level order.
OK empty tree
FAIL single node
input [[1]]
next pointers do not match the tree level order.
FAIL missing middle children
input [[1,2,3,null,5,null,7]]
next pointers do not match the tree level order.
FAIL one child
input [[1,2]]
next pointers do not match the tree level order.
Initial analysis at 4faffce:
json_next_tree in the C harness (web/compiler-explorer.js:383 at 4faffce) prints each value first and checks that node's next after. On a mismatch it closes the brackets and returns. The output is then a shorter list that still parses, and if the bad pointer is on the last node, it matches the expected answer exactly.
The C++ and Java harnesses (nextTreeToJson at line 543, nextTreeJson at line 712) and the JavaScript and Python runners (web/runners.js:604, :924) check every pointer and report the message instead of a value.
Fix: check all next pointers before printing, and print the message as a JSON string on a mismatch. json_random_list already reports its error this way in C. I will add a C toolchain test in tests/browser/compiler-explorer.test.js that fails before the fix, and send a pull request.
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
- 177
- Fork
- 100
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 182
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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
-
Selecting a pen color leaves Example drawing in eraser modeCó thể đã có người làm @Aa99841 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
sysprog21/codetrial#437 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Python tests lose every result when the solution returns inf or NaNCó thể đã có người làm @shensyuan đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
sysprog21/codetrial#419 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Allow deselecting a chosen problem card by clicking it againCó thể đã có người làm @woohsin đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
sysprog21/codetrial#392 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Audio output can be confirmed without playing a test soundCó thể đã có người làm @ChenYingHan1121 đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
sysprog21/codetrial#359 · 5 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add a Copy code button to the final reportCó thể đã có người làm @yansawu đã nhận 5 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
sysprog21/codetrial#318 · 6 bình luận · 2 reaction · 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ự
-
bug: workspace access hint suggests a --subject command that fails for hyphen-leading OIDC subjectsĐang mở
Độ 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
-
type: bug
Độ 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
-
`last_error_thread_local_then_global` fails when it runs beside the `lumen_event_detail` testĐang mởA-FFI C-Testing D-Straightforward S-Ready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
docs priority:P3 size:XS
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Appimage ConventionsĐang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày