
Asked in Razorpay
Reverse Linked List Problem Statement
Given a Singly Linked List of integers, your task is to reverse the Linked List by altering the links between the nodes.
Input:
The first line of input is an integer T, representing the number of test cases.
For each test case, the first line contains the elements of the singly linked list, separated by a space, and terminated by -1. The value -1 is not part of the list itself.
Output:
For each test case, output the reversed version of the linked list. The elements should be space-separated, ending with -1.
Provide the output for each test case on a new line.
Example:
Input:
2
1 2 3 4 5 -1
10 20 30 40 -1
Output:
5 4 3 2 1 -1
40 30 20 10 -1
Constraints:
1 <= T <= 10
1 <= N <= 10^4
0 <= data <= 10^9
Where 'N' represents the number of nodes in the linked list.
Time Limit: 1 sec
Note:
Return the head of the reversed linked list; printing is not required.
Be the first one to answer
Add answer anonymously...
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Razorpay Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

