FastPrepGenerate Circular Student Arrangements
Problem · Array

Generate Circular Student Arrangements

Learn this problem
MediumAmazon logoAmazonNEW GRADONSITE INTERVIEW
See Amazon hiring insights

Problem statement

The distinct identifiers in students must be seated around a circle. Two arrangements are considered the same if one can be rotated to obtain the other. Reflections are different because clockwise neighbor order changes.

Return every distinct circular arrangement. Serialize one arrangement by starting with the lexicographically smallest student and joining the clockwise identifiers with >. Return the serialized arrangements in lexicographic order.

Function

circularStudentArrangements(students: String[]) → String[]

Examples

Example 1

students = ["Ada","Ben","Cam"]return = ["Ada>Ben>Cam","Ada>Cam>Ben"]

Fixing Ada first leaves the clockwise orders Ben-Cam and Cam-Ben.

Example 2

students = ["Zoe","Amy"]return = ["Amy>Zoe"]

After rotations are merged, two students have one circular arrangement.

Example 3

students = ["d","b","a","c"]return = ["a>b>c>d","a>b>d>c","a>c>b>d","a>c>d>b","a>d>b>c","a>d>c>b"]

Anchoring a and permuting the other three students produces six results.

Constraints

  • 1 <= students.length <= 8.
  • Identifiers are distinct nonempty alphanumeric strings of length at most 12.
  • Identifiers do not contain >.

More Amazon problems

drafts saved locally
public String[] circularStudentArrangements(String[] students) {
  // write your code here
}
students["Ada","Ben","Cam"]
expected["Ada>Ben>Cam", "Ada>Cam>Ben"]
checking account