AlgoUniversity
  • Go Back
Discussion
Smallest Set :

Author

Ayush Kumar Shaw

Difficulty Level : Easy

Submissions : 153

Asked In : Atlassian

Marks :10

: 0 | : 1

You are given $$$n$$$ intervals of the form $$$(l_i,r_i)$$$ which contains all integers from $$$l_i$$$ to $$$r_i$$$. You need to output the size of the smallest set having atleast $$$2$$$ integers. Output $$$-1$$$ if no such interval exists.

Input

The first line contains a single integer $$$n(1 \leq n \leq 10^5)$$$. The next line contains the $$$n$$$ integers $$$l_1,l_2,...,l_n$$$. The next line contains the $$$n$$$ integers $$$r_1,r_2,...,r_n(0 \leq l_i \leq r_i \leq 10^9)$$$.

Output

Output a single integer - the answer to the problem.

Example

Input
3
1 2 3
3 4 5
Output
3

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.