Coding test from heck
Jul. 2nd, 2020 10:06 pmCoding 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... )
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... )