Find any one of multiple possible repeated integers in a list

前端 未结 6 602
一生所求
一生所求 2021-01-02 02:18

Given an array of n+1 integers, each in the range 1 to n, find an integer that is repeated.

I was asked this at a job intervi

6条回答
  •  情深已故
    2021-01-02 03:07

    How about this simple solution:

    start creating a binary search tree from the array. Whenever there is an element already present which is a duplicate while you are inserting into the BST then store that element in another array of duplicate elements and continue your loop .we don't even need to sort the array for finding the duplicates here.

    This is just my idea.I was asked the same question in one of the interviews and this was my answer.

提交回复
热议问题