FastPrepDetect a Linked-List Cycle
Problems/Detect a Linked-List Cycle

Detect a Linked-List Cycle

Paytm logoPaytm● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Paytm new grad onsite interview. A report names this well-known task. We chose the function signature, a fixed order for the output, and the input limits. Our version is about 98% the same as the reported question.

A linked list is encoded by nextIndex: node i points to node nextIndex[i], and -1 marks the end. Traversal starts at node 0.

Return whether the reachable chain contains a cycle. An empty array represents an empty list.

Function

hasCycle(nextIndex: int[]) → boolean

Examples

Example 1

nextIndex = [-1]return = false

Case 1 exercises the documented deterministic contract.

Example 2

nextIndex = [1,2,-1]return = false

Case 2 exercises the documented deterministic contract.

Example 3

nextIndex = [1,2,0]return = true

Case 3 exercises the documented deterministic contract.

Constraints

  • 0 <= nextIndex.length <= 200000.
  • Every value is -1 or a valid node index.

Source note: Author-written prompt excerpt retained for source fidelity.

More Paytm interview questions

  • Find First and Last Position in Sorted ArrayONSITE INTERVIEW · Seen Sep 2026
  • Minimum Coins for a TargetONSITE INTERVIEW · Seen Sep 2026
  • Nth Highest SalaryPHONE SCREEN · Seen Nov 2026
  • Second Highest SalaryPHONE SCREEN · Seen Nov 2026
  • Jump GamePHONE SCREEN · Seen Nov 2026
  • LRU Cache with Expiring EntriesPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Detect a Linked-List CycleCapgemini · ONSITE INTERVIEWCapgemini interview questions
  • Detect a Linked-List CycleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Detect and Remove a Linked List LoopBank of America · ONSITE INTERVIEWBank of America interview questions
  • Find a Linked-List Cycle EntryExpedia · ONSITE INTERVIEWExpedia interview questions
  • First Node Two Linked Lists ShareAdobe · PHONE SCREENAdobe interview questions
  • Check a Linked List for a CycleZillow · PHONE SCREENZillow interview questions
  • Where Two Linked Lists MeetNutanix · PHONE SCREENNutanix interview questions
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
All Paytm interview questionsSee Paytm hiring insights
Saved
class Solution {
    public boolean hasCycle(int[] nextIndex) {
        // Write your code here.
    }

}
Checking account…