FastPrepFind the Entry of a Linked List Cycle
Problems/Find the Entry of a Linked List Cycle

Find the Entry of a Linked List Cycle

Qualys logoQualys● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Qualys onsite interview. The report asks for cycle detection and the node where the cycle begins. We chose a table of links as the interface, a value to return when there is no cycle, the examples, and the limits.

Find the entry node of the cycle reachable from a singly linked list's head. The entry is the first node that would be visited twice while following successor links from the head. Return -1 if no cycle is reachable.

For this exercise, links are encoded by an array next. Node IDs are its zero-based indices; next[i] is node i's successor ID, or -1 for no successor. The head is node 0 when the array is nonempty, and an empty array is an empty list. Ignore any nodes unreachable from the head.

Return the entry node's ID, rather than its position in the traversal. Aim for O(n) time and O(1) auxiliary space.

Function

findCycleEntry(next: int[]) → int

Examples

Example 1

next = [1,2,3,1]return = 1

The traversal 0 → 1 → 2 → 3 → 1 first repeats node 1, so that node is the cycle entry.

Example 2

next = [1,-1]return = -1

The traversal terminates after nodes 0 and 1, so there is no reachable cycle.

Constraints

  • For this exercise, assume 0 <= next.length <= 10^5.
  • Each entry is -1 or a valid ID smaller than next.length.

More Qualys Onsite Interview questions

  • Delete a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
  • Implement Binary SearchONSITE INTERVIEW · Seen Oct 2026
  • Insert a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
  • Rotate an Array Right by K StepsONSITE INTERVIEW · Seen Oct 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Remove Nth Node From End of ListDruva · ONSITE INTERVIEW
  • Detect a Linked-List CyclePaytm · ONSITE INTERVIEWPaytm interview questions
  • Detect a Linked-List CycleCapgemini · ONSITE INTERVIEWCapgemini interview questions
  • Rearrange a Linked List from Alternating EndsConcentric AI · ONSITE INTERVIEWConcentric AI interview questions
  • Palindrome Linked List with RestorationMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Linked List Cycle Entry NodeGoogle · ONSITE INTERVIEWGoogle interview questions
  • Detect and Break a Linked-List CycleAmazon · ONSITE INTERVIEW
  • Odd-Even Linked ListBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Find the Entry of a Linked List CyclePeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Remove a Cycle from a Singly Linked ListExpedia · ONSITE INTERVIEWExpedia interview questions
All Qualys interview questionsSee Qualys hiring insights
Saved
class Solution {
    public int findCycleEntry(int[] next) {
        // Write your solution here.
    }
}
Checking account…