Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6454 |

@blackshadows | 6380 |

@mb1973 | 5714 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3709 |

@mantu_singh | 3556 |

@marius_valentin_dragoi | 3523 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1285 |

@gurshehzadsingh | 1052 |

@pritsahkar2000 | 812 |

@satyamchhatrala | 804 |

@nithinreddy3210 | 801 |

@iib2019024 | 745 |

@mohanreddy8847 | 704 |

@iamchaitanyahegde | 662 |

@shafeeq3543 | 651 |

@workit | 646 |

@AkashLahoty | 642 |

Complete Leaderboard |

Given two linked list of size **N1** and **N2** respectively of distinct elements, your task is to complete the function **countPairs()**, which returns the count of all pairs from both lists whose sum is equal to the given value **X**.

**Note**: The 2 numbers of a pair should be parts of different lists.

**Example 1:**

**Input:
**L1 = 1->2->3->4->5->6
L2 = 11->12->13
X = 15
**Output: **3**
Explanation: **There are 3 pairs that
add up to 15 : (4,11) , (3,12) and (2,13)

**Example 2:**

**Input:
**L1 = 7->5->1->3
L2 = 3->5->2->8
X = 10
**Output: **2**
Explanation: **There are 2 pairs that add up
to 10 : (7,3) and (5,5)

**Your Task:**

You only need to implement the given function **countPairs() **and return the count.

**Expected Time Complexity:** O(N+M)

**Expected Auxiliary Space:** O(N+M)

**Constraints:**

1<=size of linked list<=10000

1<=X<=10000

**Note** : All elements in a linked list are unique.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Count Pairs whose sum is equal to X

...