Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5594 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 783 |

@Manikanta punnam | 605 |

@sriramgoparaju99 | 578 |

@rdakka | 530 |

@praveenbgp6 | 529 |

@prankursharma31 | 518 |

@yashkaril4 | 517 |

@purohitmn02 | 467 |

@sonamnigam1999 | 443 |

@sonamkumari63928 | 441 |

@shubhamstudent5 | 433 |

Complete Leaderboard |

Given **n** integer ranges, the task is to find the maximum occurring integer in these ranges. If more than one such integer exits, find the smallest one. The ranges are given as two arrays **L**[] and **R**[]. L[i] consists of starting point of range and R[i] consists of corresponding end point of the range.

For example consider the following ranges.

L[] = {2, 1, 3}, R[] = {5, 3, 9)

Ranges represented by above arrays are.

[2, 5] = {2, **3**, 4, 5}

[1, 3] = {1, 2, **3**}

[3, 9] = {**3**, 4, 5, 6, 7, 8, 9}

The maximum occurred integer in these ranges is 3.

**Example 1:**

**Input:
**n = 4
L[] = {1,4,3,1}
R[] = {15,8,5,4}
**Output: **4**
Explanation: **The given ranges are [1,15]
[4, 8] [3, 5] [1, 4]. The number that
is most common or appears most times in
the ranges is 4.

**Example 2:**

**Input:
**n = 5
L[] = {1,5,9,13,21}
R[] = {15,8,12,20,30}
**Output: **5**
Explanation: **The given ranges are
[1,15] [5, 8] [9, 12] [13, 20]
[21, 30]. The number that is most
common or appears most times in
the ranges is 5.

**Your Task:**

The task is to complete the function **maxOccured**() which returns the maximum occured integer in all ranges.

**Expected Time Complexity:** O(n).

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

-maxx is maximum element in R[]

**Constraints:**

1 <= n <= 10^{6}

0 <= L[i], R[i] <= 10^{6}

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
Maximum occured integer

...