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

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

Can someone help me with this problem? Given an array of integers. Find the smallest positive integer which cannot be formed by performing bitwise OR on all the elements of a chosen subset. I don't know the range of n(size of the array), but what can be the most optimized approach?

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

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

Problem source?

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

The answer is the smallest power of two (or zero) which is not in the input. Since you can only generate a power of two if it is in the input. All smaller numbers can be generated from a combination of the smaller powers of two.