Skip to content

Bug Report for linked-list-cycle-detection #6036

Description

@jasonkng

Bug Report for https://neetcode.io/problems/linked-list-cycle-detection

Title: Java submission initially fails with compilation errors but is accepted after multiple resubmissions

Description

When submitting a Java solution, the first few submissions consistently fail with a compilation error. However, resubmitting the exact same code multiple times (without making any changes) eventually results in the solution being accepted.

Steps to Reproduce

  1. Open the Linked List Cycle problem.
  2. Select Java as the language.
  3. Paste a valid Java solution.
  4. Click Submit.
  5. Observe that the submission fails with a compilation error.
  6. Without modifying the code, click Submit again several times.

Expected Result

The solution should compile and be evaluated successfully on the first submission.

Actual Result

The initial submission(s) fail with a compilation error. After multiple resubmissions of the exact same code, the solution is accepted without any code changes.

Notes

  • The code is unchanged between submissions.
  • The issue appears to be intermittent and related to the submission/judging process rather than the solution itself.
  • This may indicate a problem with the Java compilation or judging infrastructure.
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */

class Solution {
    public boolean hasCycle(ListNode head) {
        ListNode fast = head, slow = head;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            if (fast == slow) {
                return true;
            }
        }
        return false;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions