Pregunta de entrevista de NVIDIA

How do you reverse the order of items in an array?

Respuestas de entrevistas

Anónimo

28 feb 2017

Do for-loop with range of loop = array.length/2 Store left and right array values into temp variables. Set right = leftTemp and left = rightTemp Index of left element = i Index of right element = array.length-i-1

Anónimo

1 may 2018

Init two pointers (p1, p2). p1 points to first element of array, p2 on last element (n-1) while loop (p1 != p2) swap values from p1 and p2 in array move p1 to next element and p2 to n-2 element (... and so on) this process repeats until p1 and p2 are at the same position and the while loop cond. is true. Needs N/2 iterations