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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if two arrays are permutations of each other using Mathematical Operation
- Minimize count of given operations required to make two given strings permutations of each other
- Create a linked list from two linked lists by choosing max element at each position
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Check if two given circles touch or intersect each other
- Check if two Integer are anagrams of each other
- C Program to check if two given strings are isomorphic to each other
- Create new linked list from two given linked list with greater element at each node
- Check if roots of a Quadratic Equation are reciprocal of each other or not
- Check if all the pairs of an array are coprime with each other
- Check if a Sequence is a concatenation of two permutations
- Count of permutations of an Array having each element as a multiple or a factor of its index
- Compare two strings represented as linked lists
- Merge two sorted linked lists such that merged list is in reverse order
- In-place Merge two linked lists without changing links of first list
- Subtract Two Numbers represented as Linked Lists
- Multiply two numbers represented as linked lists into a third list
- Union and Intersection of two linked lists | Set-2 (Using Merge Sort)
- Union and Intersection of two linked lists | Set-3 (Hashing)
- Count pairs from two linked lists whose sum is equal to a given value
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.