Jul. 2nd, 2020

chhotii: (diploma)
Coding test from heck

Recall that I had an on-line assessment for a job application, and on the second coding challenge, I derailed because for the first test case, the expected output was wrong.

Here's the question, as best I recall:

N alumni have been invited to an alumni dinner. Each alumnus is assigned a numerical ID and they are numbered starting from 1. Each alumnus likes exactly one other alumnus (although each alumnus may be liked by zero, one, or more than one other alumnus). You are given an array which gives the ID of the alumnus liked by each alumnus: for example, the array 2, 1 means that alumnus #1 likes alumnus #2 and alumnus #2 likes alumnus #1. Each alumnus will only come to the dinner if they may be seated next to the alumnus that they like. (They won't like the alumnus on their other side but that's OK.) The alumni will be seated at a circular table. Print, as a string, the seating arrangement that includes the largest number of alumni. If there's more than one such possible string, print the string that would be ordered first in lexicographical order.

In the input you are given N on the first line, and the array (space-separated) on the second line.
For example:
Input:
4
2 3 4 1

Output:
1234

Note that this works because the table is round. Alum #4 likes alum #1; they are next to each other because the first and last are adjacent.

My thoughts and solutions (plural!) and commentary below cut. Before you peek, try giving this a whack; I'm curious as to how other people find this problem.

Read more... )

Profile

chhotii: (Default)
chhotii

July 2023

S M T W T F S
      1
2345678
9101112131415
16 171819202122
23 242526272829
3031     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 25th, 2025 04:46 pm
Powered by Dreamwidth Studios