Pergunta de entrevista da empresa eBay

How would you pick the middle element of a list

Respostas da entrevista

Sigiloso

6 de nov. de 2012

its a list (assuming not an array).... Take two pointer....increment 1st pointer by 2 everytime & second by 1 [Rabbit & tortoise problem] if 1st pointer(rabbit) reaches the end of the list.... the position of the tortoise is the location of the middle element of the list.

8

Sigiloso

14 de jul. de 2015

You guys are overthinking this var arr = [1,2,3,4,5,6,7]; console.log(arr[Math.floor((arr.length - 1) / 2)]);

4

Sigiloso

30 de out. de 2012

int[] intArray = {12,34,56,78,98,31,47}; int startIndex=0; int endIndex=intArray.length -1 ; while(startIndex

1

Sigiloso

26 de set. de 2012

I said by dividing the length with 2. He said there would be two passes involved with that (?). He wanted some way with one pass.

3