AlgoUniversity
  • Go Back
Discussion
Smart Planning For Solar Powered Electric Vehicles :

Author

Shikhar Mehrotra

Difficulty Level : Medium

Submissions : 318

Asked In : Sprinklr

Marks :10

: 4 | : 5

The world is rapidly changing and getting smarter day by day. To go towards the path of sustainable development, you have decided to build a future par where you have parking space for solar-powered electric vehicles that have 0 emissions and save fuel and the environment. In the future park, the solar-powered cars need to be parked in such a way that they can get just enough sunlight in 1 hour to fully charge themselves. The current state of car parking is represented by an array $$$Current$$$ wherein the array element -1 represents the car number at that spot. You are also given an array $$$Desired$$$ which shows the ideal parking positioning of cars so that they can charge themselves fully in 1 hour. In one move, you are allowed to move a car one place forward or backward to an empty spot.

Input

The first line contains $$$1\le T \le 10^{5}$$$ denoting the number of test cases.

For each test cases: The first line contains an integer $$$1\le N \le 10^{5}$$$ denoting the size of the solar-powered car parking.

The second line contains $$$N$$$ space-separated numbers, denoting the $$$Current$$$ state of parking of solar cars.

The third line contains $$$N$$$ space-separated numbers, representing the $$$Desired$$$ state of parking solar cars.

It is also guaranteed sum of $$$N$$$ over all test cases does not exceeds $$$10^{5}$$$

Output

For each test case in a new line print the number of moves required or -1 if not possible.

Example

Input
3
4
-1 0 1 2
-1 0 1 2
4
-1 0 2 1
-1 0 1 2
4
-1 1 0 2
-1 0 1 2
Output
0
-1
1

Note

For third test case move car $$$1$$$ from position $$$2$$$ to position $$$3$$$. It would take one move. After this state would be $$${-1, 0, 1, 2}$$$.

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.