Pergunta de entrevista da empresa High Voltage

How do you reverse a linked list?

Respostas da entrevista

Sigiloso

25 de jan. de 2017

By pushing elements on a stack.

Sigiloso

8 de jun. de 2020

Do it in place with 3 pointers. Previous, current, and next. Move the pointer on current from next to previous, then advance all 3 pointers. When next is null, current becomes your new head node. This avoids expensive memory allocations and minimizes writes to RAM.