Domanda di colloquio di Dell Technologies

Sum up integer array?

Risposte di colloquio

Anonimo

18 feb 2011

lol

3

Anonimo

18 set 2012

Hi, Is the 2nd case valid? I am thinking it may not be valid since the array is an integer array ( not unsigned int ) so what if the array has an actual value of -1? Then it would terminate prematurely.

Anonimo

8 gen 2013

p-code: sum = 0, i = -1, j = arr.size(); while (++i < --j) sum += arr[i] + arr[j]; if (i == j) sum += arr[i];

Anonimo

20 feb 2011

Assuming array size is known: can be done in two ways 1) store size in the first element 2) End the last element with a sentinel value like (I feel this is more common) For 2nd case int64_t sum = 0; uint32_t index = 0; while (arr[i++] != -1) { sum+= arr[i]; } return sum;