Connection Status:
Competition Arena > PeacefulLine
SRM 647 · 2014-12-30 · by lg5293 · Simple Math
Class Name: PeacefulLine
Return Type: String
Method Name: makeLine
Arg Types: (vector<int>)
Problem Statement

Problem Statement

A teacher is trying to arrange a group of students into a line. The teacher knows that whenever she places two students with the same age next to each other, they will talk and disturb everyone. She wants to avoid that.

You are given a int[] x. Each element of x is the age of one of the students.

Determine whether it is possible for the teacher to arrange the students in a line so that there are no disturbances. If it can be done, return "possible" (quotes for clarity). If there will always be some pair of adjacent students with the same age, return "impossible". Note that the return value is case-sensitive.

Constraints

  • x will have between 1 and 25 elements, inclusive.
  • Each element of x will be between 1 and 25, inclusive.
Examples
0)
{1,2,3,4}
Returns: "possible"

In this case, no two students have the same age so any order works.

1)
{1,1,1,2}
Returns: "impossible"

Regardless of which order we choose, two of the 1s will always be adjacent.

2)
{1,1,2,2,3,3,4,4}
Returns: "possible"

One example of a peaceful line is {1,2,3,4,1,2,3,4}

3)
{3,3,3,3,13,13,13,13}
Returns: "possible"
4)
{3,7,7,7,3,7,7,7,3}
Returns: "impossible"

Submissions are judged against all 113 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class PeacefulLine with a public method string makeLine(vector<int> x) · 113 test cases · 2 s / 256 MB per case

Submitting as anonymous