Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6379 |

@blackshadows | 6329 |

@mb1973 | 5358 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@ritiksethi21 | 1050 |

@aroranayan999 | 807 |

@RizulBansal | 685 |

@ashishtrehan002 | 538 |

@hemantgarg923 | 528 |

@simrangoyal | 526 |

@ronaldo77 | 520 |

@thanosagain | 505 |

@anishrajan | 505 |

@ssparteek470 | 495 |

@rahul2312 | 491 |

Complete Leaderboard |

Given two arrays **X** and **Y** of positive integers, find the number of pairs such that **x ^{y} > y^{x}**

**Input**:
M = 3, X[] = [2 1 6]
N = 2, Y[] = [1 5]
**Output**: 3
**Explanation**:
The pairs which follow x^{y} > y^{x} are
as such: 2^{1} > 1^{2}, 2^{5} > 5^{2} and 6^{1} > 1^{6 .}

**Example 2:**

**Input**:
M = 4, X[] = [2 3 4 5]
N = 3, Y[] = [1 2 3]
**Output**: 5
**Explanation**:
The pairs for the given input are
2^{1 }> 1^{2} , 3^{1} > 1^{3 }, 3^{2} > 2^{3} , 4^{1} > 1^{4} ,
5^{1} > 1^{5 }.

**Your Task:**

This is a function problem. You only need to complete the function** countPairs() **that takes **X, Y, M, N** as **parameters **and returns the total number of pairs.

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

**Expected Auxiliary Space:** O(1).

**Constraints:**

1 ≤ M, N ≤ 10^{5}

1 ≤ X[i], Y[i] ≤ 10^{3}

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
Number of pairs

...