Skip to content

Instantly share code, notes, and snippets.

@evmorov
Last active July 7, 2016 18:16
Show Gist options
  • Save evmorov/0827cfaf1e2d820e17d27fab0819ee47 to your computer and use it in GitHub Desktop.
Save evmorov/0827cfaf1e2d820e17d27fab0819ee47 to your computer and use it in GitHub Desktop.
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