5 kyu

Can you get the loop ?

1,251 of 29,445Devouring

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 Trained98824
Total Skips25328
Total Code Submissions234640
Total Times Completed29445
Ruby Completions1251
JavaScript Completions8677
Python Completions9778
Java Completions4974
Haskell Completions652
C# Completions2263
PHP Completions549
Kotlin Completions446
C++ Completions1727
C Completions642
Total Stars2046
% of votes with a positive feedback rating88% of 3100
Total "Very Satisfied" Votes2486
Total "Somewhat Satisfied" Votes462
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