Problem Statement
We can think of a cyclic word as a word written in a circle. To represent a cyclic word, we choose an arbitrary starting position and read the characters in clockwise order. So, "picture" and "turepic" are representations for the same cyclic word.
You are given a String[] words, each element of which is a representation of a cyclic word. Return the number of different cyclic words that are represented.
You are given a String[] words, each element of which is a representation of a cyclic word. Return the number of different cyclic words that are represented.
Definition
- Class:
- CyclicWords
- Method:
- differentCW
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int differentCW(String[] words)
- (be sure your method is public)
Constraints
- words will contain between 1 and 50 elements, inclusive.
- Each element of words will contain between 1 and 50 lowercase letters ('a'-'z'), inclusive.
Examples
{ "picture", "turepic", "icturep", "word", "ordw" }Returns: 2
"picture", "turepic" and "iceturep" are representations of the same cyclic word. "word" and "ordw" are representations of a second cyclic word.{ "ast", "ats", "tas", "tsa", "sat", "sta", "ttt" }Returns: 3
{"aaaa", "aaa", "aa", "aaaa", "aaaaa"}Returns: 4