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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -