Pergunta de entrevista da empresa Google

Write a function to return the most frequently occurring number in a list (the mode).

Respostas da entrevista

Sigiloso

19 de mai. de 2016

An implementation in C could be: #include #include int mostRecurrNum(int* array, int size) { int i; int max = array[0]; for (i = 0; i max) { max = array[i]; } } int* brray = (int*)calloc(max, sizeof(int)); for (i=0; i bmax) { bmax = brray[i]; imax = i; } } return imax; } int main(void) { int A[] = {4,5,6,7,6,5,5,4,4,4,4,5,3,4,4}; int size = sizeof(A)/sizeof(A[0]); int index = mostRecurrNum(A, size); printf("Most recurring num is: %d\n", index); return 0; }

Sigiloso

19 de mai. de 2016

Correction on my previous answer max after the first foor loop should be set to: max += 1;