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

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

Find the mex of the array in o(n) time and constant space complexity; mex = smallest missing element from the array please share your ideas on this tia

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

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

Say n is the size of the array.

Loop through the array:

Let the element you are currently at be a.

If a > n, then just continue

otherwise, swap the values of the current element, and the a(th) element.

The answer will be the the (first index where the index(th) element of the list is not equal to index + 1) + 1.