5 kyu

Can you get the loop ?

1,253 of 29,672Devouring

Description:

You are given a node that is the beginning of a linked list. This list contains a dangling piece and a loop. Your objective is to determine the length of the loop.

For example in the following picture the size of the dangling piece is 3 and the loop size is 12:

# Use the `next' method to get the following node.
node.next
// Use the `getNext' method or 'next' property to get the following node.
node.getNext()
node.next
# Use the `next' attribute to get the following node
node.next
// Use the `getNext()` method to get the following node.
node.getNext()
-- use the `next :: Node a -> Node a` function to get the following node
# Use the `next' method to get the following node.
node.next
// Use the `next` field to get the following node.
Node* nextNode = nodePtr->next;
// Use the `getNext()` method to get the following node.
nodePtr->getNext()

Notes:

  • do NOT mutate the nodes!
  • in some cases there may be only a loop, with no dangling piece

Thanks to shadchnev, I broke all of the methods from the Hash class.

Don't miss dmitry's article in the discussion after you pass the Kata !!

Algorithms
Linked Lists
Performance

Stats:

CreatedDec 11, 2013
PublishedDec 12, 2013
Warriors Trained99486
Total Skips25452
Total Code Submissions235369
Total Times Completed29672
Ruby Completions1253
JavaScript Completions8719
Python Completions9886
Java Completions4995
Haskell Completions656
C# Completions2272
PHP Completions557
Kotlin Completions452
C++ Completions1755
C Completions651
Total Stars2060
% of votes with a positive feedback rating88% of 3112
Total "Very Satisfied" Votes2496
Total "Somewhat Satisfied" Votes464
Total "Not Satisfied" Votes152
Ad
Contributors
  • Devouring Avatar
  • jhoffner Avatar
  • laoris Avatar
  • dnolan Avatar
  • sridharavinash Avatar
  • tko Avatar
  • donaldsebleung Avatar
  • aweleshetu Avatar
  • Dentzil Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • ice1000 Avatar
  • frogamic Avatar
  • hobovsky Avatar
  • solitude Avatar
  • user8436785 Avatar
  • __eloise__ Avatar
  • saudiGuy Avatar
Ad