Cisco Logo

Asked in Cisco

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
Select
Add answer anonymously...

Top SDE-2 Interview Questions Asked at Cisco

Q. Can you explain the OSI model and provide an example for each layer of data tran...read more
Q. Maximum Size Rectangle Sub-matrix with All 1's Problem Statement You are provide...read more
Q. What is a NAT router?
SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits