Google | Arrange talkative students in class

I was asked this question in telephonic round of Google. Couldn't come to any good solution .. Any idea how to approach ?

There are multiple students in a class.. They speak various languages . For example (input),
Students: [S1, S2, S3, S4, S5]
Languages: [L1, L1, L2, L2, L3]

Teacher of their class wants student not to talk to each other. She can do this by making student sit in such a fashion that , for every student , adjacent student speaks different langauge.

Output :
(1 possible arrangment)
[S1, S3, S2, S4, S5]

Assumption :

  1. Input ia valid & intented arrangment is possible.
  2. There is just 1 row which has seats exactly equal to # of students.
  3. All students just speak exactly 1 language
Comments (5)