Блог пользователя coder_getsetgo

Автор coder_getsetgo, история, 5 лет назад, По-английски

Hello Everyone,

I recently encountered this problem in an Interview.

You are given N. You have to construct an array of 2*N size with conditions:

  1. You have to use a number from 1 to N that means each number must be used exactly twice.

  2. Distance between indices of the same number should be equal to (number + 1).

The output should be true if the construction of such an array is possible else it should be false.

EG: Input 3 Output true

Explanation: possible array is [2, 3, 1, 2, 1, 3]

Note: The bounds on N were not given in the question.

Can anybody help me with this?

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by coder_getsetgo (previous revision, new revision, compare).

»
5 лет назад, # |
  Проголосовать: нравится +64 Проголосовать: не нравится

Did someone really ask this on a face-to-face coding interview, and expected you to come up with an answer on the spot without knowing the solution beforehand?

»
5 лет назад, # |
  Проголосовать: нравится +22 Проголосовать: не нравится