Company: Barclays
Difficulty: medium
Alumni Dinner Seating Arrangement A University has invited N alumni for a dinner. The dinner table has a circular shape. Each alumnus is assigned an invitation ID from 0 to N-1. Each alumnus likes exactly one fellow alumnus and will attend the dinner only if he/she can be seated next to the person he/she likes. Write an algorithm to find the IDs of the alumni in a lexicographical order so that maximum number of alumni attend the dinner. If more than one such seating arrangement exists, then output the one that is lexicographically smaller. Input Format The first line of the input consists of an integer num , representing the number of alumni (N). The second line consists of N space-separated integers, alumniID[0] , alumniID[1] ,...., alumniID[N-1] representing the ID of the person whom the i th alumnus likes. Output Format Print space-separated integers representing the IDs of the alumni who will attend the dinner. Note One alumnus can be liked by multiple alumni. Constraints 1 ≤ num ≤