Pergunta de entrevista da empresa Apple

Eliminate duplicates from an array

Resposta da entrevista

Sigiloso

9 de nov. de 2018

#include using namespace std; int main() { int i, j; int k = 0; int a[7] = {1,1,2,3,4,4,5}; // set array int n = 7; for(i = 0; i< 7; i++) // list all elements { for(j = i+1; j<7; j++) // a for loop for the next element { if (a[i] == a[j]) // if the first element = the next, { // get new array for (k = j; k< n-1; k++)// allow repeted array to be equaling the next while skipping repatead cell { a[k] = a[k+1]; n --; // reduce size of array if there is duplicate } } else { j++ ; // check the next element } } } for (i = 0; i< n;++i) { cout<< a[i] ; } return 0; }