algorithm - output one arrangement of n people everyone has k friends, -
this interview question, given n people, output 1 arrangement has k friends. n>k. possible no answer, i.e. if both n , k odd number, no answer. naive pick k friends each people may not return solution, i.e. n=6, k=4, may end 5 people friends each other, , 1 left no friends. fast algorithm question? , there similar question?
arrange in circle.
- for k, have friends people within k/2 spots them.
- for odd k , n, have friends people within (k-1)/2 spots them , person across them.
- for odd k , odd n, there no solution.
Comments
Post a Comment