Last active
July 7, 2016 18:16
-
-
Save evmorov/0827cfaf1e2d820e17d27fab0819ee47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(a) | |
dup_elem_grouped = a.group_by { |e| e }.find { |k, v| v.size > 1 } | |
return 1 unless dup_elem_grouped | |
pos_start = a[a.index(dup_elem_grouped.first)] | |
pos_current = a[pos_start] | |
circle_size = 1 | |
until pos_start == pos_current | |
pos_current = a[pos_current] | |
circle_size += 1 | |
end | |
circle_size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment