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

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

Recently I encountered the following problem in the recruitment test for IBM research.

There is an array of size K with elements from 1 to N and an array of size N with elements from 1 to K. Prove that there exists a sub-array of the first array and a sub-array of the second array with the same sum.

I was thinking of applying pigeonhole principle using difference of prefix sums but could not get anything concrete. Any ideas about how to prove this ?

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

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится -38 Проголосовать: не нравится

both of them have a sub-array of sum 1

EDIT: just removed an annoyingly large image

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

    There isn't every element presented neccesarily. If N=2, K=5, then arrays can be e.g. {2,2,2,2,2} and {3,5}.

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

Nice problem. It is quite not straightforward, so no shame if you can't solve it. Not going to burn the IBM interview question though, because it is hard to find nice problems like this. Usually interviewers give hints for such hard problems or don't expect the candidate to fully solve it, looking at approaches the candidate tries to use.

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