Empty arrays
Practice
3.2 (18 votes)
Data structures
Queues
Basics of queues
Problem
69% Success 4631 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given two arrays each of size $$n$$, $$a$$ and $$b$$ consisting of the first $$n$$ positive integers each exactly once, that is, they are permutations. 

Your task is to find the minimum time required to make both the arrays empty. The following two types of operations can be performed any number of times each taking 1 second:

  • In the first operation, you are allowed to rotate the first array clockwise.
  • In the second operation, when the first element of both the arrays is the same, they are removed from both the arrays and the process continues.

Input format

  • The first line contains an integer $$n$$, denoting the size of the array.
  • The second line contains the elements of array $$a$$.
  • The third line contains the elements of array $$b$$.

Output format

Print the total time taken required to empty both the array.

Constraints

$$1 \le n \le 100$$

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
48 votes
Tags:
Data StructuresEasyHash MapsPriority queueQueue