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

Автор i_am_not_special, история, 2 года назад, По-английски

You are given an array a of integers with n elements. You are allowed to rearrange the elements of the array in any order. Your task is to determine if it is possible to reorder the array such that for every i from 0 to n-2 (i.e., for all adjacent elements), the absolute difference between consecutive elements is either 5 or 7. That is, for all i such that 0 <= i < n — 1, you need to check if: abs(v[i] — v[i + 1]) = 5 or abs(v[i] — v[i+ 1]) = 7.

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

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

What is the expected time complexity?

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

what are the constraints on a[i]?

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

I think I solved it. Lets discuss in the dm. But damn this was such a good question. You should have offered it as a problem in a contest. Please ping in dm.

»
2 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

ignore plz

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

Just writing whatever comes into my faulty memory at this point, but I think I faced a similar problem in an OA once and later found out that such problems are solved my building a graph out of it and determining the maximum flow or something similar on that line, I am not educated on the algorithm yet.

I dont believe theres a simpler solution but I'd be happy if someone figures it out.