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.
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}$$$
For each test case in a new line print the number of moves required or -1 if not possible.
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
0 -1 1
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.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.