You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:
A large-scale backend system processes streams of events using linked data structures for efficient insertions and deletions. In some workflows such as rollback operations, cache reordering, or pipeline rewiring, the system needs to reverse the order of elements in a singly linked list.
Each node in the list contains a value and a reference to the next node.
The system requires an in-place solution that efficiently reverses the list without allocating extra memory.
This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.
Your Task
Given the head of a singly linked list, reverse the list and return the new head.
You must reverse the list in place.
Input Format
head: the head node of a singly linked list
Each node is defined as:
ListNode {
int val;
ListNode next;
}
Output Format
- Return the head of the reversed linked list