Given two linked lists(can be sorted or unsorted) of size n1 and n2 of distinct elements. Given a value X. The problem is to count all pairs from both lists whose product is equal to the given value x.
Note:The pair must have an element from each linked list.
Input : list1 = 3->1->5->7 list2 = 8->2->5->3 X = 10 Output : 1 The pair is: (5, 2) Input : list1 = 4->3->5->7->11->2->1 list2 = 2->3->4->5->6->8-12 X = 9 Output : 1 The pair is: (3, 3)
A simple approach is using two loops pick elements from both the linked lists and check whether the product of the pair is equal to the given value X or not. Count all such pairs and print the result.
Below is the implementation of the above approach:
Count = 1
Time complexity : O(N^2)
- Count pairs from two linked lists whose sum is equal to a given value
- Count triplets in a sorted doubly linked list whose product is equal to a given value x
- Find a triplet from three linked lists with sum equal to a given number
- Find pairs with given product in a sorted Doubly Linked List
- Count pairs in a binary tree whose sum is equal to a given value x
- Find count of common nodes in two Doubly Linked Lists
- Count triplets in a sorted doubly linked list whose sum is equal to a given value x
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
- Identical Linked Lists
- Check if two Linked Lists are permutations of each other
- Add two numbers represented by linked lists | Set 2
- Union and Intersection of two Linked Lists
- Merge Sort for Linked Lists
- Intersection of two Sorted 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 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.
Improved By : VishalBachchas