Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

In an Array with integers between 1 and 1 000 000 one value is duplicated How do you determine which one is duplicated?

user-image
Question added by Deleted user
Date Posted: 2016/01/04
Dana Qaisi
by Dana Qaisi , Social Media Specialist , N/A

  1. Have a hash table
  2. Iterate through array and store its elements in hash table
  3. As soon as you find an element which is already in hash table, it is the dup element
  • Pros:
    • It runs in O(n) time and with only1 pass
    Cons:
    • It uses O(n) extra memory

Yahya Mubaideen
by Yahya Mubaideen , Operations Officer , Experience Jordan Adventures

if it's sorted use a variable to store first integer and iterate while comparing like this:

int iterator=0

int temp

do{

temp = array[iterator]

iterator+1

}while(temp != array[iterator])

 

if not sorted either sort with the fastest sorting algorithm available to you then use above method

 

Deleted user
by Deleted user

créer deux tableaux vides un contient le tableau sans récurrence et l'autre contient les valeurs répété puis parcourir le tableau a "N" fois chaque fois lire l'index N est comparer avec tout les cellules de tableau sauf le case N si il existe donc il y a une récurrence quelque part  si non le valeur n’existe pas, par contre partie si le valeur existe ajouter dans le tableau qui contient les répétition si non ajoute dans le tableau des valeur non itérative   ,

Waleed Elgalab
by Waleed Elgalab , Senior Business System Analyst , Naseej

1- Define a variable to store the the duplicated index, outside the loop2- Loop through the array elements from index:0 to index: not-->> to prevent the comparison from exceeding the array Upper Bound

3- Compare equality between the current element value and the next one 

4- If there a duplication store it's index in the breviously defined variable

More Questions Like This