An interview question (Detect cycles in a sequence of numbers)# JobHunting - 待字闺中
c*5
1 楼
Detecting Cycles
Description:
Given a sequence, write a program to detect cycles within it.
Input sample:
A file containing a sequence of numbers (space delimited). The file can have
multiple such lines. e.g
2 0 6 3 1 6 3 1 6 3 1
Ensure to account for numbers that have more than one digit eg. 12. If there
is no sequence, ignore that line.
Output sample:
Print to stdout the first sequence you find in each line. Ensure that there
are no trailing empty spaces on each line you print. e.g.
6 3 1
Any good idea?
Thanks a lot.
Description:
Given a sequence, write a program to detect cycles within it.
Input sample:
A file containing a sequence of numbers (space delimited). The file can have
multiple such lines. e.g
2 0 6 3 1 6 3 1 6 3 1
Ensure to account for numbers that have more than one digit eg. 12. If there
is no sequence, ignore that line.
Output sample:
Print to stdout the first sequence you find in each line. Ensure that there
are no trailing empty spaces on each line you print. e.g.
6 3 1
Any good idea?
Thanks a lot.