Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6381 |

@blackshadows | 6329 |

@mb1973 | 5388 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@1905439 | 553 |

@terabaap123 | 508 |

@smitadiwedi1991 | 279 |

@DevanandJayakumar | 250 |

@atishagusain | 244 |

@gupta_10 | 226 |

@nipun edara | 224 |

@shubhamkhullar7 | 224 |

@sharmachandan487 | 204 |

@balunagar | 204 |

@arshjit_singh7 | 190 |

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?

Yes
Count Pairs whose sum is equal to X

...