ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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
تم إضافة السؤال من قبل مستخدم محذوف‎
تاريخ النشر: 2016/01/04
Dana Qaisi
من قبل 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
من قبل 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

 

مستخدم محذوف‎
من قبل مستخدم محذوف‎

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
من قبل 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

المزيد من الأسئلة المماثلة