Given two singly Linked list of integer data. The task is to write a program that efficiently checks if two linked lists are permutations of each other.
Input: 1 -> 2 -> 3 -> 4 -> 5 2 -> 1 -> 3 -> 5 -> 4 Output: Yes Input: 10 -> 20 -> 30 -> 40 20 -> 50 -> 60 -> 70 Output: No
Approach: Do the following for both linked lists:
- Take a temporary node pointing to the head of the linked list.
- Start traversing through the linked list, and keep sum and multiplications of data of nodes.
Note : After having sum and multiplication of both linked list, check if sum and multiplication of both linked lists are equal. If they are equal, it means linked lists are permutations of each other, else not.
Below is the implementation of the above approach:
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Check if two arrays are permutations of each other using Mathematical Operation
- Identical Linked Lists
- Add two numbers represented by linked lists | Set 2
- Add two numbers represented by linked lists | Set 1
- First common element in two linked lists
- Merge Sort for Linked Lists
- Intersection of two Sorted Linked Lists
- Merge K sorted linked lists | Set 1
- Merge two sorted linked lists
- Union and Intersection of two Linked Lists
- Compare two strings represented as linked lists
- Find common elements in three linked lists
- Longest common suffix of two linked lists
- Multiply two numbers represented by Linked Lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.