FazeelUsmani / Amazon-SDE-Preparation

This repository includes all the interview preparation questions for Amazon SDE role
https://practice.geeksforgeeks.org/batch/Amazon-Test-Series
1.12k stars 291 forks source link

07 Linked List --> 4. Reverse a Linked List #83

Closed FazeelUsmani closed 3 years ago

FazeelUsmani commented 3 years ago

Given a linked list of N nodes. The task is to reverse this list.

Example 1:

Input: LinkedList: 1->2->3->4->5->6 Output: 6 5 4 3 2 1 Explanation: After reversing the list, elements are 6->5->4->3->2->1. Example 2:

Input: LinkedList: 2->7->8->9->10 Output: 10 9 8 7 2 Explanation: After reversing the list, elements are 10->9->8->7->2. Your Task: The task is to complete the function reverseList() with head reference as the only argument and should return new head after reversing the list.

Expected Time Complexity: O(N). Expected Auxiliary Space: O(1).

Constraints: 1 <= N <= 104

Amisha328 commented 3 years ago

Hi there! I would like to contribute to this.

FazeelUsmani commented 3 years ago

Sure, @Amisha328. Assigning

Amisha328 commented 3 years ago

Thank you @FazeelUsmani.

gursparsh commented 3 years ago

Hi! I would like to contribute to this

FazeelUsmani commented 3 years ago

Sure, @gursparsh. Assigning you