Pergunta de entrevista da empresa Qualcomm

Given a LinkedList, return the value in the middle.

Respostas da entrevista

Sigiloso

6 de mar. de 2017

Have a tracker Node that starts at the LinkedList's head and a counter integer. For-each loop through the LinkedList and increment the counter by 1 every loop iteration. Only increment the tracker Node ( ie. tracker = tracker.next() ) whenever counter % 2 == 0 and counter != 0. Return the tracker after the for-each loop finishes iterating.

Sigiloso

5 de out. de 2018

Make two pointers. Start the first one going at a regular pace: Node.next(), while the other one goes twice as fast. Node.next().next(). Once the the one going twice as fast reaches the end, you’ll know that the first one is at the middle. 👌🏽